]> Some of my projects - localmylist.git/commitdiff
Change the way episode types are stored
authorAPTX <marek321@gmail.com>
Mon, 23 Jul 2012 18:37:54 +0000 (20:37 +0200)
committerAPTX <marek321@gmail.com>
Mon, 23 Jul 2012 18:37:54 +0000 (20:37 +0200)
localmylist/database.cpp
localmylist/database.h
localmylist/mylistexportparsetask.cpp
localmylist/requesthandler.cpp
localmylist/scriptable.cpp
localmylist/scriptable.h
localmylist/share/schema/default_config.sql
localmylist/share/schema/schema.sql

index bb7da03e80c40cfd469d2efe06c01c11ef67414b..cfd540e6707bca0303760a00993fd4eb301e284f 100644 (file)
@@ -40,10 +40,7 @@ Episode::Episode()
        epno = 0;
        length = 0;
        state = 0;
-       special = false;
        recap = false;
-       opening = false;
-       ending = false;
        rating = 0;
        votes = 0;
        myVote = 0;
@@ -498,7 +495,7 @@ QList<Episode> Database::getEpisodes(int aid)
        QSqlQuery &q = prepare(
        "SELECT e.eid, e.aid, e.anidb_update, e.entry_update, e.my_update, e.epno, "
        "               e.title_english, e.title_romaji, e.title_kanji, e.length, e.airdate, e.state, "
-       "               e.special, e.recap, e.opening, e.ending, e.rating, e.votes, e.my_vote, e.my_vote_date "
+       "               e.type, e.recap, e.rating, e.votes, e.my_vote, e.my_vote_date "
        "       FROM episode e "
        "       JOIN anime a ON (a.aid = e.aid)"
        "       WHERE a.aid = :aid ");
@@ -525,7 +522,7 @@ Episode Database::getEpisode(int eid)
        QSqlQuery &q = prepare(
        "SELECT eid, aid, anidb_update, entry_update, my_update, epno, "
        "               title_english, title_romaji, title_kanji, length, airdate, state, "
-       "               special, recap, opening, ending, rating, votes, my_vote, my_vote_date "
+       "               type, recap, rating, votes, my_vote, my_vote_date "
        "       FROM episode "
        "       WHERE eid = :eid ");
 
@@ -687,8 +684,8 @@ bool Database::setEpisode(const Episode &episode)
        "               aid = :aid, anidb_update = :anidbUpdate, entry_update = :entryUpdate, "
        "               my_update = :myUpdate, epno = :epno, title_english = :titleEnglish, "
        "               title_romaji = :titleRomaji, title_kanji = :titleKanji, length = :length, "
-       "               airdate = :airdate, state = :state, special = :special, recap = :recap, "
-       "               opening = :opening, ending = :ending, rating = :rating, votes = :votes, "
+       "               airdate = :airdate, state = :state, type = :type, recap = :recap, "
+       "               rating = :rating, votes = :votes, "
        "               my_vote = :myVote, my_vote_date = :myVoteDate "
        "       WHERE eid = :eid ");
 
@@ -704,10 +701,8 @@ bool Database::setEpisode(const Episode &episode)
        q.bindValue(":length", episode.length);
        q.bindValue(":airdate", episode.airdate);
        q.bindValue(":state", episode.state);
-       q.bindValue(":special", episode.special);
+       q.bindValue(":type", episode.type);
        q.bindValue(":recap", episode.recap);
-       q.bindValue(":opening", episode.opening);
-       q.bindValue(":ending", episode.ending);
        q.bindValue(":rating", episode.rating);
        q.bindValue(":votes", episode.votes);
        q.bindValue(":myVote", episode.myVote);
@@ -818,7 +813,7 @@ bool Database::addEpisode(const Episode &episode)
        QSqlQuery &q = prepare(
        "INSERT INTO episode VALUES(:eid, :aid, :anidbUpdate, :entryUpdate, :myUpdate, :epno, "
        "               :titleEnglish, :titleRomaji, :titleKanji, :length, :airdate, "
-       "               :state, :special, :recap, :openineg, :ending, :rating, "
+       "               :state, :type, :recap, :rating, "
        "               :votes, :myVote, :myVoteDate) ");
 
        q.bindValue(":eid", episode.eid);
@@ -833,10 +828,8 @@ bool Database::addEpisode(const Episode &episode)
        q.bindValue(":length", episode.length);
        q.bindValue(":airdate", episode.airdate);
        q.bindValue(":state", episode.state);
-       q.bindValue(":special", episode.special);
+       q.bindValue(":type", episode.type);
        q.bindValue(":recap", episode.recap);
-       q.bindValue(":opening", episode.opening);
-       q.bindValue(":ending", episode.ending);
        q.bindValue(":rating", episode.rating);
        q.bindValue(":votes", episode.votes);
        q.bindValue(":myVote", episode.myVote);
@@ -1371,14 +1364,12 @@ Episode Database::readEpisode(QSqlQuery &q)
        e.length = q.value(9).toInt();
        e.airdate = q.value(10).toDateTime();
        e.state = q.value(11).toInt();
-       e.special = q.value(12).toBool();
+       e.type = q.value(12).toString();
        e.recap = q.value(13).toBool();
-       e.opening = q.value(14).toBool();
-       e.ending = q.value(15).toBool();
-       e.rating = q.value(16).toDouble();
-       e.votes = q.value(17).toInt();
-       e.myVote = q.value(18).toDouble();
-       e.myVoteDate = q.value(19).toDateTime();
+       e.rating = q.value(14).toDouble();
+       e.votes = q.value(15).toInt();
+       e.myVote = q.value(16).toDouble();
+       e.myVoteDate = q.value(17).toDateTime();
 
        return e;
 }
index 3c0b96b5c483eab5e7b6a8630e66d073644301f6..8db95df27e8869051fa6538a57286e91303a06fe 100644 (file)
@@ -69,10 +69,8 @@ struct LOCALMYLISTSHARED_EXPORT Episode
        int length;
        QDateTime airdate;
        int state;
-       bool special;
+       QString type;
        bool recap;
-       bool opening;
-       bool ending;
        double rating;
        int votes;
        double myVote;
index e17478f31d768dc144ed1d2aac5146ab87cc199b..d95d85709b2b9873662e9f8dea3d6ca34ea8927c 100644 (file)
@@ -335,16 +335,19 @@ void MyListExportParseTask::readEpisode()
                                e.state = readElementText().toInt();
                        }
                        else if (name() == "EpStateSpecial") {
-                               e.special = bool(readElementText().toInt());
+                               if (bool(readElementText().toInt()))
+                                       e.type = "S";
                        }
                        else if (name() == "EpStateRecap") {
                                e.recap = bool(readElementText().toInt());
                        }
                        else if (name() == "EpStateOp") {
-                               e.opening = bool(readElementText().toInt());
+                               if (bool(readElementText().toInt()))
+                                       e.type = "C";
                        }
                        else if (name() == "EpStateEnd") {
-                               e.ending = bool(readElementText().toInt());
+                               if (bool(readElementText().toInt()))
+                                       e.type = "C";
                        }
                        else if (name() == "EpRating") {
                                e.rating = readElementText().toDouble();
@@ -399,10 +402,8 @@ qDebug() << "Updating Episode" << current.eid;
                if (e.airdate.isValid())
                        current.airdate = e.airdate;
                current.state = e.state;
-               current.special = e.special;
+               current.type = e.type;
                current.recap = e.recap;
-               current.opening = e.opening;
-               current.ending = e.ending;
        }else{qDebug() << "No update required" << current.eid;}
 
        current.entryUpdate = QDateTime::currentDateTime();
index 2c34ea9a5704942fc29924eab3b88f9502a315fb..b762bb117e8b64a77bab2d5f29fa478b4e07a506 100644 (file)
@@ -245,11 +245,9 @@ void RequestHandler::episodeRequestComplete(bool success)
        next.length = reply->length();
        next.airdate = reply->airDate();
        //      next.state - State is a bitfield and will be split into parts
-       next.special = reply->type() == 'S';
-       // I see no way of getting these via UDP api.
+       next.type = reply->type();
+       // I see no way of getting this via UDP api.
        //      next.recap
-       //      next.opening
-       //      next.ending
        next.rating = reply->rating();
        next.votes = reply->votes();
 
index 47ee47994177ea0c82373033d96b784436d18809..eb557e45bc4499117546707bd0ade41d51f2702f 100644 (file)
@@ -738,18 +738,18 @@ void Episode::write_state(int val)
        o->state = val;
 }
 
-bool Episode::read_special() const
+QString Episode::read_type() const
 {
        auto o = thisObj();
-       if (!o) return bool();
-       return o->special;
+       if (!o) return QString();
+       return o->type;
 }
 
-void Episode::write_special(bool val)
+void Episode::write_type(QString val)
 {
        auto o = thisObj();
        if (!o) return;
-       o->special = val;
+       o->type = val;
 }
 
 bool Episode::read_recap() const
@@ -766,34 +766,6 @@ void Episode::write_recap(bool val)
        o->recap = val;
 }
 
-bool Episode::read_opening() const
-{
-       auto o = thisObj();
-       if (!o) return bool();
-       return o->opening;
-}
-
-void Episode::write_opening(bool val)
-{
-       auto o = thisObj();
-       if (!o) return;
-       o->opening = val;
-}
-
-bool Episode::read_ending() const
-{
-       auto o = thisObj();
-       if (!o) return bool();
-       return o->ending;
-}
-
-void Episode::write_ending(bool val)
-{
-       auto o = thisObj();
-       if (!o) return;
-       o->ending = val;
-}
-
 double Episode::read_rating() const
 {
        auto o = thisObj();
index 3b2f7f7c5173ac99d71fa70a20eea76ee378fe44..ac140fe0cf2524d7d9924d86f3392a99832948f8 100644 (file)
@@ -171,10 +171,8 @@ class LOCALMYLISTSHARED_EXPORT Episode : public QObject, protected QScriptable
        Q_PROPERTY(int length READ read_length WRITE write_length)
        Q_PROPERTY(QDateTime airdate READ read_airdate WRITE write_airdate)
        Q_PROPERTY(int state READ read_state WRITE write_state)
-       Q_PROPERTY(bool special READ read_special WRITE write_special)
+       Q_PROPERTY(QString type READ read_type WRITE write_type)
        Q_PROPERTY(bool recap READ read_recap WRITE write_recap)
-       Q_PROPERTY(bool opening READ read_opening WRITE write_opening)
-       Q_PROPERTY(bool ending READ read_ending WRITE write_ending)
        Q_PROPERTY(double rating READ read_rating WRITE write_rating)
        Q_PROPERTY(int votes READ read_votes WRITE write_votes)
        Q_PROPERTY(double myVote READ read_myVote WRITE write_myVote)
@@ -224,18 +222,12 @@ public:
        int read_state() const;
        void write_state(int val);
 
-       bool read_special() const;
-       void write_special(bool val);
+       QString read_type() const;
+       void write_type(QString val);
 
        bool read_recap() const;
        void write_recap(bool val);
 
-       bool read_opening() const;
-       void write_opening(bool val);
-
-       bool read_ending() const;
-       void write_ending(bool val);
-
        double read_rating() const;
        void write_rating(double val);
 
index b429cf00e3b13431723648915de2a43b6ab6f999..633b699a024ff35f840d1c7ea2e48f9af501fb1d 100644 (file)
@@ -24,3 +24,13 @@ INSERT INTO config VALUES ('renameLanguage', NULL, true);
 INSERT INTO config VALUES ('enableRename', '0', true);
 
 INSERT INTO config VALUES ('fileFilters', '*.mkv *.mp4 *.ogg *.ogm *.wmv *.avi *.mpg *.flv', true);
+
+
+-- Episode types
+INSERT INTO episode_type VALUES ('', 'Normal', 0);
+INSERT INTO episode_type VALUES ('S', 'Special', 1);
+INSERT INTO episode_type VALUES ('C', 'Credits/Opening/Ending', 2);
+INSERT INTO episode_type VALUES ('T', 'Trailer/Promo/Ads', 3);
+INSERT INTO episode_type VALUES ('P', 'Parody/Fandub', 4);
+INSERT INTO episode_type VALUES ('O', 'Other', 5);
+INSERT INTO episode_type VALUES ('OP', 'Opening/Ending', 6);
index 5f38802817403b6a764952cfec62e1ad0856da18..e7fdc98eb3b65e0082054eac2a661b7a4f9a1671 100644 (file)
@@ -1,3 +1,5 @@
+CREATE TYPE episode_type_enum AS ENUM ('', 'S', 'C', 'T', 'P', 'O', 'OP');
+
 CREATE TABLE anime (
        aid integer NOT NULL,
        anidb_update timestamp without time zone,
@@ -52,10 +54,8 @@ CREATE TABLE episode (
        length integer,
        airdate timestamp without time zone,
        state integer,
-       special boolean,
+       type episode_type_enum NOT NULL DEFAULT '',
        recap boolean,
-       opening boolean,
-       ending boolean,
        rating numeric(4,2),
        votes integer,
        my_vote numeric(4,2),
@@ -64,6 +64,14 @@ CREATE TABLE episode (
 );
 CREATE INDEX episode_aid_fk ON episode USING btree (aid);
 
+CREATE TABLE episode_type
+(
+       type episode_type_enum NOT NULL,
+       name character varying(200),
+       ordering integer NOT NULL DEFAULT 0,
+       CONSTRAINT episode_type_pk PRIMARY KEY (type )
+);
+
 CREATE TABLE file (
        fid integer NOT NULL,
        eid integer,
@@ -207,7 +215,7 @@ CREATE VIEW rename_data AS
                        a.temp_rating, a.temp_votes, a.my_vote AS anime_my_vote, a.my_vote_date AS anime_my_vote_date, a.my_temp_vote, a.my_temp_vote_date,
                        (SELECT max(episode.epno) AS highest_epno FROM episode WHERE episode.aid = f.aid) AS highest_epno,
                e.anidb_update AS episode_anidb_update, e.entry_update AS episode_entry_update, e.my_update AS episode_my_update, e.epno, e.title_english AS episode_title_english, e.title_romaji AS episode_title_romaji,
-                       e.title_kanji AS episode_title_kanji, e.length AS episode_length, e.airdate, e.state, e.special, e.recap, e.opening, e.ending, e.rating, e.votes, e.my_vote, e.my_vote_date,
+                       e.title_kanji AS episode_title_kanji, e.length AS episode_length, e.airdate, e.state, e.type, e.recap, e.rating, e.votes, e.my_vote, e.my_vote_date,
                f.anidb_update, f.entry_update, f.my_update, f.ed2k, f.size, f.length, f.extension, f.group_name, f.group_name_short, f.crc, f.release_date, f.version, f.censored, f.source, f.quality_id,
                        f.quality, f.resolution, f.video_codec, f.audio_codec, f.audio_language, f.subtitle_language, f.aspect_ratio, f.my_watched, f.my_state, f.my_file_state, f.my_storage, f.my_source,
                        f.my_other, fl.host_id, fl.path, fl.renamed, fl.failed_rename