From: APTX Date: Mon, 22 Apr 2013 01:02:04 +0000 (+0200) Subject: Proper handling of file.quality. X-Git-Url: https://gitweb.aptx.org/?a=commitdiff_plain;h=3091642fa7fed8a7c170709fb0fa728482bf1ffe;p=localmylist.git Proper handling of file.quality. This is a significant schema change. For upgrading see: http://localmylist.aptx.org/w/Upgrade/quality_enum --- diff --git a/localmylist/database.cpp b/localmylist/database.cpp index 0c3b143..1ec1395 100644 --- a/localmylist/database.cpp +++ b/localmylist/database.cpp @@ -518,7 +518,7 @@ File Database::getFile(int fid) QSqlQuery &q = prepare( "SELECT fid, eid, aid, gid, lid, entry_added, anidb_update, entry_update, my_update, " " ed2k, size, length, extension, group_name, group_name_short, crc, " - " release_date, version, censored, deprecated, source, quality_id, quality, resolution, " + " release_date, version, censored, deprecated, source, quality, resolution, " " video_codec, audio_codec, audio_language, subtitle_language, aspect_ratio, " " my_watched, my_state, my_file_state, my_storage, my_source, my_other " " FROM file " @@ -548,7 +548,7 @@ File Database::getFileByPath(const QString &path) QSqlQuery &q = prepare( "SELECT f.fid, f.eid, f.aid, f.gid, f.entry_added, 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.release_date, f.version, f.censored, f.source, 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 " " FROM file f " @@ -574,7 +574,7 @@ File Database::getFileByTitle(const QString &title, int epno) QSqlQuery &q = prepare( "SELECT f.fid, f.eid, f.aid, f.gid, f.entry_added, 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.release_date, f.version, f.censored, f.source, 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 " " FROM file f " @@ -585,7 +585,7 @@ File Database::getFileByTitle(const QString &title, int epno) "UNION " "SELECT f.fid, f.eid, f.aid, f.gid, f.entry_added, 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.release_date, f.version, f.censored, f.source, 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 " " FROM file f " @@ -596,7 +596,7 @@ File Database::getFileByTitle(const QString &title, int epno) " AND e.epno = :epno " "GROUP BY f.fid, f.eid, f.aid, f.gid, f.entry_added, 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.release_date, f.version, f.censored, f.source, 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 "); @@ -698,7 +698,7 @@ bool Database::setFile(const File &file) " ed2k = :ed2k, size = :size, length = :length, extension = :extension, " " group_name = :groupName, group_name_short = :groupNameShort, crc = :crc, " " release_date = :releaseDate, version = :version, censored = :censored, " - " deprecated = :deprecated, source = :source, quality_id = :qualityId, quality = :quality, " + " deprecated = :deprecated, source = :source, quality = :quality, " " resolution = :resolution, video_codec = :videoCodec, " " audio_codec = :audioCodec, audio_language = :audioLanguage, " " subtitle_language = :subtitleLanguage, aspect_ratio = :aspectRatio, " @@ -726,7 +726,6 @@ bool Database::setFile(const File &file) q.bindValue(":censored", file.censored); q.bindValue(":deprecated", file.deprecated); q.bindValue(":source", file.source); - q.bindValue(":qualityId", file.qualityId); q.bindValue(":quality", file.quality); q.bindValue(":resolution", file.resolution); q.bindValue(":videoCodec", file.videoCodec); @@ -857,7 +856,7 @@ bool Database::addFile(const File &file) QSqlQuery &q = prepare( "INSERT INTO file VALUES(:fid, :eid, :aid, :gid, :lid, DEFAULT, :anidbUpdate, :entryUpdate, :myUpdate, " " :ed2k, :size, :length, :extension, :groupName, :groupNameShort, " - " :crc, :releaseDate, :version, :censored, :deprecated, :source, :qualityId, " + " :crc, :releaseDate, :version, :censored, :deprecated, :source, " " :quality, :resolution, :vidoeCodec, :audioCodec, :audioLanguage, " " :subtitleLanguage, :aspectRatio, :myWatched, :myState, " " :myFileState, :myStorage, :mySource, :myOther) "); @@ -882,7 +881,6 @@ bool Database::addFile(const File &file) q.bindValue(":censored", file.censored); q.bindValue(":deprecated", file.deprecated); q.bindValue(":source", file.source); - q.bindValue(":qualityId", file.qualityId); q.bindValue(":quality", file.quality); q.bindValue(":resolution", file.resolution); q.bindValue(":videoCodec", file.videoCodec); @@ -1524,7 +1522,6 @@ void Database::readFileData(SqlResultIteratorInterface &result, File &data, int data.censored = result.value(offset++).toBool(); data.deprecated = result.value(offset++).toBool(); data.source = result.value(offset++).toString(); - data.qualityId = result.value(offset++).toInt(); data.quality = result.value(offset++).toString(); data.resolution = result.value(offset++).toString(); data.videoCodec = result.value(offset++).toString(); @@ -1618,7 +1615,7 @@ QString Database::fileFields() return "f.fid, f.eid, f.aid, f.gid, f.lid, f.entry_added, 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.deprecated, f.source, f.quality_id, f.quality, f.resolution, " + "f.release_date, f.version, f.censored, f.deprecated, f.source, 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 "; } @@ -1725,7 +1722,6 @@ File Database::readFile(QSqlQuery &q) f.version = q.value(16).toInt(); f.censored = q.value(17).toBool(); f.source = q.value(18).toString(); - f.qualityId = q.value(19).toInt(); f.quality = q.value(20).toString(); f.resolution = q.value(21).toString(); f.videoCodec = q.value(22).toString(); diff --git a/localmylist/databaseclasses.cpp b/localmylist/databaseclasses.cpp index c49a075..1f14245 100644 --- a/localmylist/databaseclasses.cpp +++ b/localmylist/databaseclasses.cpp @@ -50,7 +50,6 @@ File::File() version = 1; censored = false; deprecated = false; - qualityId = 0; myState = 0; myFileState = 0; } diff --git a/localmylist/databaseclasses.h b/localmylist/databaseclasses.h index c3cd270..83245cd 100644 --- a/localmylist/databaseclasses.h +++ b/localmylist/databaseclasses.h @@ -103,7 +103,6 @@ struct LOCALMYLISTSHARED_EXPORT File bool censored; bool deprecated; QString source; - int qualityId; QString quality; QString resolution; QString videoCodec; diff --git a/localmylist/mylistexportparsetask.cpp b/localmylist/mylistexportparsetask.cpp index 9b60ee9..296e829 100644 --- a/localmylist/mylistexportparsetask.cpp +++ b/localmylist/mylistexportparsetask.cpp @@ -503,9 +503,6 @@ void MyListExportParseTask::readFile() else if (name() == "TypeName") { f.source = readElementText(); } - else if (name() == "QualityID") { - f.qualityId = readElementText().toInt(); - } else if (name() == "QualityName") { f.quality = readElementText(); } @@ -609,8 +606,6 @@ qDebug() << "Updating File" << current.fid; current.censored = f.censored; if (!f.source.isEmpty()) current.source = f.source; - if (f.qualityId) - current.qualityId = f.qualityId; if (!f.quality.isEmpty()) current.quality = f.quality; if (!f.resolution.isEmpty()) diff --git a/localmylist/requesthandler.cpp b/localmylist/requesthandler.cpp index acc58f8..759b4ae 100644 --- a/localmylist/requesthandler.cpp +++ b/localmylist/requesthandler.cpp @@ -351,7 +351,6 @@ void RequestHandler::fileRequestComplete(bool success) next.censored = reply->isCensored(); next.deprecated = reply->isDeprecated(); next.source = reply->source(); - // next.qualityId - can map quality to qualityId next.quality = reply->quality(); next.resolution = reply->videoResolution(); next.videoCodec = reply->videoCodec(); diff --git a/localmylist/scriptable.cpp b/localmylist/scriptable.cpp index e4a6e73..fff61a7 100644 --- a/localmylist/scriptable.cpp +++ b/localmylist/scriptable.cpp @@ -1118,20 +1118,6 @@ void File::write_source(QString val) o->source = val; } -int File::read_qualityId() const -{ - auto o = thisObj(); - if (!o) return int(); - return o->qualityId; -} - -void File::write_qualityId(int val) -{ - auto o = thisObj(); - if (!o) return; - o->qualityId = val; -} - QString File::read_quality() const { auto o = thisObj(); diff --git a/localmylist/scriptable.h b/localmylist/scriptable.h index 3e994a9..a3e4976 100644 --- a/localmylist/scriptable.h +++ b/localmylist/scriptable.h @@ -271,7 +271,6 @@ class LOCALMYLISTSHARED_EXPORT File : public QObject, protected QScriptable Q_PROPERTY(int version READ read_version WRITE write_version) Q_PROPERTY(bool censored READ read_censored WRITE write_censored) Q_PROPERTY(QString source READ read_source WRITE write_source) - Q_PROPERTY(int qualityId READ read_qualityId WRITE write_qualityId) Q_PROPERTY(QString quality READ read_quality WRITE write_quality) Q_PROPERTY(QString resolution READ read_resolution WRITE write_resolution) Q_PROPERTY(QString videoCodec READ read_videoCodec WRITE write_videoCodec) @@ -351,9 +350,6 @@ public: QString read_source() const; void write_source(QString val); - int read_qualityId() const; - void write_qualityId(int val); - QString read_quality() const; void write_quality(QString val); diff --git a/localmylist/share/schema/default_config.sql b/localmylist/share/schema/default_config.sql index 9c380dd..3658387 100644 --- a/localmylist/share/schema/default_config.sql +++ b/localmylist/share/schema/default_config.sql @@ -34,3 +34,13 @@ 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); + +-- Qualities +INSERT INTO quality VALUES ('unknown', 1, 7); +INSERT INTO quality VALUES ('very high', 2, 0); +INSERT INTO quality VALUES ('high', 3, 1); +INSERT INTO quality VALUES ('med', 4, 2); +INSERT INTO quality VALUES ('low', 5, 3); +INSERT INTO quality VALUES ('very low', 6, 4); +INSERT INTO quality VALUES ('corrupted', 7, 5); +INSERT INTO quality VALUES ('eyecancer', 8, 6); diff --git a/localmylist/share/schema/schema.sql b/localmylist/share/schema/schema.sql index fc031c0..49a6f63 100644 --- a/localmylist/share/schema/schema.sql +++ b/localmylist/share/schema/schema.sql @@ -1,5 +1,8 @@ DROP TYPE IF EXISTS episode_type_enum; CREATE TYPE episode_type_enum AS ENUM ('', 'S', 'C', 'T', 'P', 'O'); +DROP TYPE IF EXISTS quality_enum; +CREATE TYPE quality_enum AS ENUM ('unknown', 'very high', 'high', 'med', + 'low', 'very low', 'corrupted', 'eyecancer'); CREATE TABLE anime ( aid integer NOT NULL, @@ -97,8 +100,7 @@ CREATE TABLE file ( censored boolean, deprecated boolean DEFAULT false, source character varying(50), - quality_id integer, - quality character varying(50), + quality quality_enum NOT NULL, resolution character varying(50), video_codec character varying(50), audio_codec character varying(50), @@ -116,6 +118,15 @@ CREATE TABLE file ( CREATE INDEX file_aid_fk ON file USING btree (aid); CREATE INDEX file_eid_fk ON file USING btree (eid); +CREATE TABLE quality +( + quality quality_enum NOT NULL, + quality_id integer NOT NULL, + ordering integer NOT NULL DEFAULT 0, + CONSTRAINT quality_pk PRIMARY KEY (quality ), + CONSTRAINT quality_id_unique UNIQUE (quality_id ) +); + CREATE TABLE file_episode_rel ( fid integer NOT NULL, eid integer NOT NULL, @@ -140,6 +151,7 @@ CREATE TABLE file_location ( CONSTRAINT file_location_pk PRIMARY KEY (location_id ), CONSTRAINT file_location_unique_location UNIQUE (fid, host_id, path ) ); +CREATE INDEX file_location_fid_fk ON file_location USING btree (fid); CREATE TABLE unknown_file ( ed2k character(32) NOT NULL, @@ -245,9 +257,6 @@ CREATE TABLE log ( CONSTRAINT log_pk PRIMARY KEY (log_id) ); -CREATE VIEW file_data AS - SELECT f.fid, f.eid, f.aid, f.gid, 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.deprecated, 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, a.title_romaji AS atitle, e.title_english AS eptitle FROM ((file f LEFT JOIN anime a ON ((f.aid = a.aid))) LEFT JOIN episode e ON ((f.eid = e.eid))); - CREATE VIEW rename_data AS SELECT f.fid, f.eid, f.aid, f.gid, a.anidb_update AS anime_anidb_update, a.entry_update AS anime_entry_update, a.my_update AS anime_my_update, a.title_english AS anime_title_english, a.title_romaji AS anime_title_romaji, a.title_kanji AS anime_title_kanji, a.description, a.year, a.start_date, a.end_date, a.type AS anime_type, a.total_episode_count, a.highest_epno, a.rating AS anime_rating, a.votes AS anime_votes, @@ -260,13 +269,14 @@ CREATE VIEW rename_data AS FROM file f JOIN anime a ON a.aid = f.aid JOIN episode e ON e.eid = f.eid + JOIN episode_type et ON et.type = e.type + JOIN quality q ON q.quality = f.quality JOIN file_location fl ON fl.fid = f.fid; --- WHEN (OLD.* IS DISTINCT FROM NEW.*) <- means if anything changed CREATE OR REPLACE RULE anime_update_rename_rule AS ON UPDATE TO anime WHERE old.aid = new.aid - AND (old.title_english <> new.title_english OR old.title_romaji <> new.title_romaji OR old.title_kanji <> new.title_kanji OR old.description <> new.description OR old.year <> new.year OR old.start_date <> new.start_date OR old.end_date <> new.end_date OR old.type::text <> new.type::text OR old.total_episode_count <> new.total_episode_count OR old.highest_epno <> new.highest_epno OR old.rating <> new.rating OR old.votes <> new.votes OR old.temp_rating <> new.temp_rating OR old.temp_votes <> new.temp_votes) + AND (old.* IS DISTINCT FROM new.*) DO UPDATE file_location fl SET renamed = NULL FROM file f WHERE f.fid = fl.fid AND f.aid = old.aid; @@ -274,7 +284,7 @@ CREATE OR REPLACE RULE anime_update_rename_rule AS CREATE OR REPLACE RULE episode_update_rename_rule AS ON UPDATE TO episode WHERE old.eid = new.eid - AND (old.aid <> new.aid OR old.epno <> new.epno OR old.title_english <> new.title_english OR old.title_romaji <> new.title_romaji OR old.title_kanji <> new.title_kanji OR old.length <> new.length OR old.airdate <> new.airdate OR old.state <> new.state OR old.type <> new.type OR old.recap <> new.recap OR old.rating <> new.rating OR old.votes <> new.votes) + AND (old.* IS DISTINCT FROM new.*) DO UPDATE file_location fl SET renamed = NULL FROM file f WHERE f.fid = fl.fid AND f.eid = old.eid; @@ -282,7 +292,7 @@ CREATE OR REPLACE RULE episode_update_rename_rule AS CREATE OR REPLACE RULE file_update_rename_rule AS ON UPDATE TO file WHERE old.fid = new.fid - AND (old.eid <> new.eid OR old.aid <> new.aid OR old.gid <> new.gid OR old.ed2k <> new.ed2k OR old.size <> new.size OR old.length <> new.length OR old.extension::text <> new.extension::text OR old.group_name <> new.group_name OR old.group_name_short <> new.group_name_short OR old.crc <> new.crc OR old.release_date <> new.release_date OR old.version <> new.version OR old.censored <> new.censored OR old.source::text <> new.source::text OR old.quality_id <> new.quality_id OR old.quality::text <> new.quality::text OR old.resolution::text <> new.resolution::text OR old.video_codec::text <> new.video_codec::text OR old.audio_codec::text <> new.audio_codec::text OR old.audio_language::text <> new.audio_language::text OR old.subtitle_language::text <> new.subtitle_language::text OR old.aspect_ratio::text <> new.aspect_ratio::text) + AND (old.* IS DISTINCT FROM new.*) DO UPDATE file_location fl SET renamed = NULL WHERE fl.fid = old.fid;