]> Some of my projects - localmylist.git/commitdiff
Prefer the file with the highest resolution in firstUnwatched* methods.
authorAPTX <marek321@gmail.com>
Sun, 21 Apr 2013 16:57:54 +0000 (18:57 +0200)
committerAPTX <marek321@gmail.com>
Sun, 21 Apr 2013 16:57:54 +0000 (18:57 +0200)
localmylist/database.cpp

index aba24478300510abc58472489092129fd80f95fd..72b771bc4d79782f40210160e78b662b38d6b992 100644 (file)
@@ -88,7 +88,9 @@ return false;
 OpenFileData Database::firstUnwatchedByExactTitle(const QString &title)
 {
        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 anime_title at ON f.aid = at.aid "
        "       LEFT JOIN episode e ON f.eid = e.eid "
@@ -102,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 ");
+       "ORDER BY epno ASC, pixels DESC ");
        q.bindValue(":title", title);
 
        return readOpenFileData(q);
@@ -118,7 +120,9 @@ OpenFileData Database::firstUnwatchedByTitle(const QString &title)
                return ofd;
 
        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 anime_title at ON f.aid = at.aid "
        "       LEFT JOIN episode e ON f.eid = e.eid "
@@ -132,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 ");
+       "ORDER BY epno ASC, pixels DESC ");
        q.bindValue(":fuzzyTitle", "%" + title + "%");
 
        ofd = readOpenFileData(q);