]> Some of my projects - localmylist.git/commitdiff
Add openEpisode method to to open a specific episode.
authorAPTX <marek321@gmail.com>
Sat, 31 Aug 2013 15:54:01 +0000 (17:54 +0200)
committerAPTX <marek321@gmail.com>
Sat, 31 Aug 2013 15:54:01 +0000 (17:54 +0200)
localmylist/database.cpp
localmylist/database.h

index c2cb4c2be42a2de3d100c83fa3e03dd51e3fbe5c..34c0d617c31ac5d78850f240f3ec5eb4bc29d6df 100644 (file)
@@ -362,6 +362,27 @@ OpenFileData Database::openFile(int fid)
        return readOpenFileData(q);
 }
 
+OpenFileData Database::openEpisode(int aid, int epno, const QString &type)
+{
+       QSqlQuery &q = prepare(
+       "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 "
+       "       WHERE f.aid = :aid "
+       "               AND e.epno = :epno "
+       "               AND e.type = :type "
+       "               AND fl.path IS NOT NULL "
+       "ORDER BY pixels DESC, f.version DESC ");
+       q.bindValue(":aid", aid);
+       q.bindValue(":epno", epno);
+       q.bindValue(":type", type);
+
+       return readOpenFileData(q);
+}
+
 HostInfo Database::getHostInfo(const QString &hostName)
 {
        QSqlQuery &q = prepare(
index 89a8bf8f461d0c08ada1e6a3b8401a82157e080b..8d7f329060b644cb5930dfbdfb81d561364fdaf6 100644 (file)
@@ -57,6 +57,7 @@ public slots:
        LocalMyList::OpenFileData openFileByTitle(const QString &title, int epno = 0);
        LocalMyList::OpenFileData openFileByEid(int eid);
        LocalMyList::OpenFileData openFile(int fid);
+       LocalMyList::OpenFileData openEpisode(int aid, int epno, const QString &type = "");
 
        LocalMyList::HostInfo getHostInfo(const QString &hostName);