]> Some of my projects - localmylist.git/commitdiff
Prefer the file with the highest version (and pixels) in firstUnwatched*
authorAPTX <marek321@gmail.com>
Tue, 7 May 2013 20:37:29 +0000 (22:37 +0200)
committerAPTX <marek321@gmail.com>
Tue, 7 May 2013 20:37:29 +0000 (22:37 +0200)
localmylist/database.cpp

index 32ca5c0e449e3e2a05397f27f70e223774317635..b2a59340654d760e52e4763164305c3427e87441 100644 (file)
@@ -104,7 +104,7 @@ OpenFileData Database::firstUnwatchedByExactTitle(const QString &title)
        "                       SELECT 1 FROM file f "
        "                               JOIN file_episode_rel fer ON fer.eid = e.eid AND f.fid = fer.fid "
        "                               WHERE my_watched IS NOT NULL) "
-       "ORDER BY epno ASC, pixels DESC ");
+       "ORDER BY epno ASC, pixels DESC, f.version DESC ");
        q.bindValue(":title", title);
 
        return readOpenFileData(q);
@@ -136,7 +136,7 @@ OpenFileData Database::firstUnwatchedByTitle(const QString &title)
        "                       SELECT 1 FROM file f "
        "                               JOIN file_episode_rel fer ON fer.eid = e.eid AND f.fid = fer.fid "
        "                               WHERE my_watched IS NOT NULL) "
-       "ORDER BY epno ASC, pixels DESC ");
+       "ORDER BY epno ASC, pixels DESC, f.version DESC ");
        q.bindValue(":fuzzyTitle", "%" + title + "%");
 
        ofd = readOpenFileData(q);
@@ -147,7 +147,9 @@ OpenFileData Database::firstUnwatchedByTitle(const QString &title)
 OpenFileData Database::firstUnwatchedByAid(int aid)
 {
        QSqlQuery &q = prepare(
-       "SELECT f.fid, a.title_romaji, e.title_english, e.epno, fl.path, fl.host_id FROM file f "
+       "SELECT f.fid, a.title_romaji, e.title_english, e.epno, fl.path, fl.host_id, "
+       "               CASE WHEN split_part(f.resolution, 'x', 1) = '' OR split_part(f.resolution, 'x', 2) = '' THEN 0 ELSE split_part(f.resolution, 'x', 1)::int * split_part(f.resolution, 'x', 2)::int END pixels "
+       "       FROM file f "
        "       LEFT JOIN anime a ON f.aid = a.aid "
        "       LEFT JOIN episode e ON f.eid = e.eid "
        "       LEFT JOIN file_location fl ON fl.fid = f.fid "
@@ -155,7 +157,7 @@ OpenFileData Database::firstUnwatchedByAid(int aid)
        "               AND f.aid = :aid "
        "               AND fl.path IS NOT NULL "
        "               AND NOT EXISTS (SELECT 1 FROM file WHERE eid = e.eid AND my_watched IS NOT NULL LIMIT 1) "
-       "ORDER BY e.epno ASC ");
+       "ORDER BY e.epno ASC, pixels DESC, f.version DESC ");
        q.bindValue(":aid", aid);
 
        return readOpenFileData(q);