[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [jungle/mockPoc] /: Add a simple TvDbJob
From:       Vishesh Handa <me () vhanda ! in>
Date:       2014-10-01 0:18:32
Message-ID: E1XZ7cm-00045S-W6 () scm ! kde ! org
[Download RAW message or body]

Git commit d9c0f76ede7efa965bc2cb9c5b08b5bb4eb64839 by Vishesh Handa.
Committed on 29/09/2014 at 22:23.
Pushed by vhanda into branch 'mockPoc'.

Add a simple TvDbJob

It only works for movies right now, and the test is honestly quite
shitty. We will need to mock out the TvDbQt library if we want to test
this out properly.

M  +8    -0    autotest/CMakeLists.txt
A  +92   -0    autotest/tvdbjobtest.cpp     [License: LGPL (v2.1+)]
A  +110  -0    src/tvdbjob.cpp     [License: LGPL (v2.1+)]
A  +52   -0    src/tvdbjob.h     [License: LGPL (v2.1+)]

http://commits.kde.org/jungle/d9c0f76ede7efa965bc2cb9c5b08b5bb4eb64839

diff --git a/autotest/CMakeLists.txt b/autotest/CMakeLists.txt
index 2552047..03eac3f 100644
--- a/autotest/CMakeLists.txt
+++ b/autotest/CMakeLists.txt
@@ -61,3 +61,11 @@ ecm_add_test(guessitjobtest.cpp
     TEST_NAME "guessItJobTest"
     LINK_LIBRARIES ${GMOCK_LIBRARIES} ${GTEST_LIBRARIES} Qt5::Test pthread
 )
+
+ecm_add_test(tvdbjobtest.cpp
+    ../src/tvdbjob.cpp
+
+    TEST_NAME "tvDbJobTest"
+    LINK_LIBRARIES ${GMOCK_LIBRARIES} ${GTEST_LIBRARIES} Qt5::Test pthread
+                   TmdbQt::TmdbQt5
+)
diff --git a/autotest/tvdbjobtest.cpp b/autotest/tvdbjobtest.cpp
new file mode 100644
index 0000000..948515d
--- /dev/null
+++ b/autotest/tvdbjobtest.cpp
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2014  Vishesh Handa <me@vhanda.in>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include "tvdbjob.h"
+#include "interfaces/dataqueueinterface.h"
+#include "shared.h"
+
+#include <QTest>
+#include <QVariantMap>
+#include <QDebug>
+
+#include <tmdbqt/themoviedbapi.h>
+
+class TvDbJobTest : public QObject
+{
+    Q_OBJECT
+private Q_SLOTS:
+    void testMovie();
+    void testInvalidMovie();
+    void testMultipleMovieResults();
+};
+
+class MockDataQueue : public DataQueueInterface
+{
+public:
+    MOCK_METHOD1(add, void(const QVariantMap&));
+};
+
+// Issued to vhanda for personal use
+static const char* s_key = "d27948732458af6587dbc9b9764aad37";
+
+void TvDbJobTest::testMovie()
+{
+    const QString url("/home/vishesh/Shrek.2001.mp4");
+
+    QVariantMap input;
+    input["type"] = "movie";
+    input["filePath"] = url;
+    input["title"] = "Shrek";
+    input["year"] = 2001;
+
+    QVariantMap data = input;
+    data["posterUrl"] = \
"http://image.tmdb.org/t/p/w342/140ewbWv8qHStD3mlBDvvGd0Zvu.jpg"; +
+    MockDataQueue dataQueue;
+    EXPECT_CALL(dataQueue, add(data)).Times(1);
+
+    QList<DataQueueInterface*> queues;
+    queues << &dataQueue;
+
+    TmdbQt::TheMovieDbApi api(QString::fromLatin1(s_key));
+    // FIXME: There must be a better way?
+    QEventLoop loop;
+    connect(&api, SIGNAL(initialized()), &loop, SLOT(quit()));
+    loop.exec();
+
+    Jungle::TvDbJob job(api, input, queues);
+    job.start();
+
+    QTest::qWait(10000);
+}
+
+void TvDbJobTest::testInvalidMovie()
+{
+
+}
+
+void TvDbJobTest::testMultipleMovieResults()
+{
+
+}
+
+
+QTEST_GMOCK_MAIN(TvDbJobTest);
+
+#include "tvdbjobtest.moc"
diff --git a/src/tvdbjob.cpp b/src/tvdbjob.cpp
new file mode 100644
index 0000000..ca2dcd7
--- /dev/null
+++ b/src/tvdbjob.cpp
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2014  Vishesh Handa <me@vhanda.in>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include "tvdbjob.h"
+
+#include <tmdbqt/searchjob.h>
+#include <tmdbqt/moviedblist.h>
+
+#include <QDebug>
+#include <QUrl>
+
+using namespace Jungle;
+
+TvDbJob::TvDbJob(TmdbQt::TheMovieDbApi& api, const QVariantMap& input, \
QList<DataQueueInterface*> queues) +    : QObject()
+    , m_inputData(input)
+    , m_queues(queues)
+    , m_api(api)
+{
+}
+
+void TvDbJob::start()
+{
+    if (!m_api.isInitialized()) {
+        qWarning() << "TvDbApi is not initialized";
+        return;
+    }
+
+    QString type = m_inputData.value("type").toString();
+    if (type == QStringLiteral("movie")) {
+        QString name = m_inputData.value("title").toString();
+        int year = m_inputData.value("year").toInt();
+
+        TmdbQt::SearchJob* job = m_api.searchMovie(name, year);
+        connect(job, SIGNAL(result(TmdbQt::SearchJob*)),
+                this, SLOT(slotMovieResult(TmdbQt::SearchJob*)));
+        qDebug();
+    }
+    else if (type == QStringLiteral("episode")) {
+        //
+        // How do we implement this exactly?
+        // We get the following objects -
+        // 1. Tv Show
+        // 2. Tv Season
+
+        // We cannot actually get much info about the tv show. Or can we?
+        // We could get the tv show object + tv season object
+        // and just add them
+
+        /*
+        QString series = m_inputData.value("series");
+        int episodeNumber = m_inputData.value("episodeNumber");
+        int season = m_inputData.value("season");
+        */
+
+        // TvShow fetch job gives us - tvshow + tv season (partial info)
+        // We need an extra tvseason fetch job which gives us the episodes
+        // and then we need to collate it with the url
+
+        // TODO
+        // 1. Fetch the series info
+        // 2. Fetch the season - no that should go in another job?
+    }
+
+}
+
+void TvDbJob::slotMovieResult(TmdbQt::SearchJob* job)
+{
+    TmdbQt::MovieDbList list = job->result();
+    if (list.isEmpty()) {
+        qWarning() << "Could not find anything for" << m_inputData;
+        return;
+    }
+
+    TmdbQt::MovieDb movie = list.first();
+    int year = m_inputData.value("year").toInt();
+
+    // A simple heuristic in case of multiple results
+    for (const TmdbQt::MovieDb& mov : list) {
+        if (mov.releaseDate().year() == year) {
+            movie = mov;
+            break;
+        }
+    }
+
+    QVariantMap output = m_inputData;
+    output["title"] = movie.title();
+    output["posterUrl"] = movie.posterUrl(QLatin1String("w342"));
+
+    for (DataQueueInterface* queue : m_queues) {
+        queue->add(output);
+    }
+}
+
diff --git a/src/tvdbjob.h b/src/tvdbjob.h
new file mode 100644
index 0000000..8f0f342
--- /dev/null
+++ b/src/tvdbjob.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2014  Vishesh Handa <me@vhanda.in>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifndef JUNGLE_TVDBJOB_H
+#define JUNGLE_TVDBJOB_H
+
+#include <QObject>
+#include "interfaces/dataqueueinterface.h"
+
+#include <tmdbqt/searchjob.h>
+#include <tmdbqt/themoviedbapi.h>
+
+namespace Jungle {
+
+class TvDbJob : public QObject
+{
+    Q_OBJECT
+public:
+    TvDbJob(TmdbQt::TheMovieDbApi& api, const QVariantMap& input,
+            QList<DataQueueInterface*> queues);
+
+    void start();
+
+private Q_SLOTS:
+     void slotMovieResult(TmdbQt::SearchJob*);
+
+private:
+    QVariantMap m_inputData;
+    QList<DataQueueInterface*> m_queues;
+
+    TmdbQt::TheMovieDbApi& m_api;
+};
+
+}
+
+#endif // JUNGLE_TVDBJOB_H


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic