]> Some of my projects - localmylist.git/commitdiff
Add nextEpisode and previousEpisode.
authorAPTX <marek321@gmail.com>
Sat, 16 Aug 2014 15:42:13 +0000 (17:42 +0200)
committerAPTX <marek321@gmail.com>
Sat, 16 Aug 2014 15:42:13 +0000 (17:42 +0200)
The intended use is for players requesting a file
for the next/previous episode in a series.

localmylist/database.cpp
localmylist/database.h

index 83eb1300f68cea982c6865e80e968b89508a14fa..03f99dd5491895668f82ffb3fc3d7fd4dc574d1e 100644 (file)
@@ -463,6 +463,54 @@ OpenFileData Database::openEpisode(int aid, int epno, const QString &type)
        return readOpenFileData(q);
 }
 
+OpenFileData Database::nextEpisode(int fid)
+{
+       QSqlQuery &q = prepare(R"(
+       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
+               JOIN episode e ON f.eid = e.eid
+               JOIN anime a ON a.aid = f.aid
+               JOIN file_location fl ON fl.fid = f.fid
+               WHERE f.fid = (SELECT f2.fid
+                       FROM file f
+                       JOIN episode e ON f.eid = e.eid
+                       JOIN episode e2 ON e2.aid = e.aid AND ((e2.epno > e.epno AND e2.type = e.type) OR e2.type > e.type) -- No type ordering here (but it works as the enum is ordered)
+                       JOIN episode_type et ON et.type = e2.type
+                       JOIN file f2 ON f2.eid = e2.eid AND f2.fid <> f.fid
+                       WHERE f.fid = :fid
+                       ORDER BY et.ordering DESC, e2.epno ASC -- et.ordering should be DESC: 99 -> S1 (not O1)
+                       LIMIT 1)
+       )");
+       q.bindValue(":fid", fid);
+
+       return readOpenFileData(q);
+}
+
+OpenFileData Database::previousEpisode(int fid)
+{
+       QSqlQuery &q = prepare(R"(
+       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
+               JOIN episode e ON f.eid = e.eid
+               JOIN anime a ON a.aid = f.aid
+               JOIN file_location fl ON fl.fid = f.fid
+               WHERE f.fid = (SELECT f2.fid
+                       FROM file f
+                       JOIN episode e ON f.eid = e.eid
+                       JOIN episode e2 ON e2.aid = e.aid AND ((e2.epno < e.epno AND e2.type = e.type) OR e2.type < e.type) -- No type ordering here (but it works as the enum is ordered)
+                       JOIN episode_type et ON et.type = e2.type
+                       JOIN file f2 ON f2.eid = e2.eid AND f2.fid <> f.fid
+                       WHERE f.fid = :fid
+                       ORDER BY et.ordering ASC, e2.epno DESC -- et.ordering should be ASC: C1 -> S99 (not 99)
+                       LIMIT 1)
+       )");
+       q.bindValue(":fid", fid);
+
+       return readOpenFileData(q);
+}
+
 HostInfo Database::getHostInfo(const QString &hostName)
 {
        QSqlQuery &q = prepare(
index 902ee37d48d963a50f614ea89cddfa98449f072b..de7e97a24e9f5581581f3837e77c7bb52c0a98aa 100644 (file)
@@ -72,6 +72,20 @@ public slots:
        LocalMyList::OpenFileData openFile(int fid);
        LocalMyList::OpenFileData openEpisode(int aid, int epno, const QString &type = "");
 
+       /**
+        * @brief nextEpisode return the next available episode
+        * @param fid the id for which the next episode is to be found
+        * @return OpenFileData with fid != 0 if a next episode is found
+        */
+       LocalMyList::OpenFileData nextEpisode(int fid);
+
+       /**
+        * @brief previousEpisode return the prefioud available episode
+        * @param fid the id for which the previous episode is to be found
+        * @return OpenFileData with fid != 0 if a previous episode is found
+        */
+       LocalMyList::OpenFileData previousEpisode(int fid);
+
        LocalMyList::HostInfo getHostInfo(const QString &hostName);
 
        QVariantMap getConfig();