File indexing completed on 2024-05-12 16:46:20

0001 /***************************************************************************
0002     Copyright (C) 2009-2020 Robby Stephenson <robby@periapsis.org>
0003  ***************************************************************************/
0004 
0005 /***************************************************************************
0006  *                                                                         *
0007  *   This program is free software; you can redistribute it and/or         *
0008  *   modify it under the terms of the GNU General Public License as        *
0009  *   published by the Free Software Foundation; either version 2 of        *
0010  *   the License or (at your option) version 3 or any later version        *
0011  *   accepted by the membership of KDE e.V. (or its successor approved     *
0012  *   by the membership of KDE e.V.), which shall act as a proxy            *
0013  *   defined in Section 14 of version 3 of the license.                    *
0014  *                                                                         *
0015  *   This program is distributed in the hope that it will be useful,       *
0016  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0017  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0018  *   GNU General Public License for more details.                          *
0019  *                                                                         *
0020  *   You should have received a copy of the GNU General Public License     *
0021  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
0022  *                                                                         *
0023  ***************************************************************************/
0024 
0025 #undef QT_NO_CAST_FROM_ASCII
0026 
0027 #include "imdbfetchertest.h"
0028 
0029 #include "../fetch/imdbfetcher.h"
0030 #include "../entry.h"
0031 #include "../collections/videocollection.h"
0032 #include "../collectionfactory.h"
0033 #include "../images/imagefactory.h"
0034 #include "../fieldformat.h"
0035 #include "../fetch/fetcherjob.h"
0036 
0037 #include <KSharedConfig>
0038 
0039 #include <QTest>
0040 
0041 QTEST_GUILESS_MAIN( ImdbFetcherTest )
0042 
0043 ImdbFetcherTest::ImdbFetcherTest() : AbstractFetcherTest() {
0044 }
0045 
0046 void ImdbFetcherTest::initTestCase() {
0047   Tellico::ImageFactory::init();
0048   Tellico::RegisterCollection<Tellico::Data::VideoCollection> registerVideo(Tellico::Data::Collection::Video, "video");
0049 
0050   m_config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)->group(QStringLiteral("IMDB"));
0051   m_config.writeEntry("Custom Fields", QStringLiteral("alttitle,imdb,imdb-rating,origtitle"));
0052 }
0053 
0054 void ImdbFetcherTest::init() {
0055   // reset to english every time
0056   m_config.writeEntry("Lang", QStringLiteral("0"));
0057 }
0058 
0059 void ImdbFetcherTest::testSnowyRiver() {
0060   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title, QStringLiteral("The Man From Snowy River"));
0061   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::IMDBFetcher(this));
0062   fetcher->readConfig(m_config);
0063 
0064   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0065 
0066   QCOMPARE(results.size(), 1);
0067 
0068   // the first entry had better be the right one
0069   Tellico::Data::EntryPtr entry = results.at(0);
0070 
0071   QCOMPARE(entry->field("title"), QStringLiteral("The Man from Snowy River"));
0072   QCOMPARE(entry->field("year"), QStringLiteral("1982"));
0073   QCOMPARE(set(entry, "genre"), set("Adventure; Drama; Romance; Western"));
0074   QCOMPARE(entry->field("nationality"), QStringLiteral("Australia"));
0075   QCOMPARE(set(entry, "studio"), set("Cambridge Productions; Michael Edgley International; Snowy River Investment Pty. Ltd."));
0076   QCOMPARE(entry->field("running-time"), QStringLiteral("102"));
0077   QCOMPARE(entry->field("audio-track"), QStringLiteral("Dolby"));
0078   QCOMPARE(entry->field("aspect-ratio"), QStringLiteral("2.35 : 1"));
0079   QCOMPARE(entry->field("color"), QStringLiteral("Color"));
0080   QCOMPARE(entry->field("language"), QStringLiteral("English"));
0081   QCOMPARE(entry->field("certification"), QStringLiteral("PG (USA)"));
0082   QCOMPARE(entry->field("director"), QStringLiteral("George Miller"));
0083   QCOMPARE(entry->field("producer"), QStringLiteral("Geoff Burrowes"));
0084   QCOMPARE(entry->field("composer"), QStringLiteral("Bruce Rowland"));
0085   QCOMPARE(set(entry, "writer"), set("Cul Cullen; A.B. 'Banjo' Paterson;John Dixon"));
0086   QStringList castList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("cast")));
0087   QVERIFY(!castList.isEmpty());
0088   QCOMPARE(castList.at(0), QStringLiteral("Tom Burlinson::Jim Craig"));
0089   QCOMPARE(entry->field("imdb"), QStringLiteral("https://www.imdb.com/title/tt0084296/"));
0090   QVERIFY(!entry->field("imdb-rating").isEmpty());
0091   QVERIFY(!entry->field("plot").isEmpty());
0092   QVERIFY(!entry->field("plot").contains('>'));
0093   QVERIFY(!entry->field("cover").isEmpty());
0094   QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/')));
0095   QStringList altTitleList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("alttitle")));
0096   QVERIFY(altTitleList.contains(QStringLiteral("Herencia de un valiente")));
0097   QVERIFY(!entry->field("alttitle").contains(QStringLiteral("See more")));
0098 }
0099 
0100 void ImdbFetcherTest::testSnowyRiverFr() {
0101   m_config.writeEntry("Lang", QStringLiteral("1")); // french
0102 
0103   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title, "The Man From Snowy River");
0104   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::IMDBFetcher(this));
0105   fetcher->readConfig(m_config);
0106 
0107   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0108 
0109   QCOMPARE(results.size(), 1);
0110 
0111   // the first entry had better be the right one
0112   Tellico::Data::EntryPtr entry = results.at(0);
0113 
0114   QCOMPARE(entry->field("title"), QString::fromUtf8("L'homme de la rivière d'argent"));
0115   QCOMPARE(entry->field("year"), QLatin1String("1982"));
0116   QCOMPARE(set(entry->field("genre")), set(QLatin1String("Aventure; Drame; Romantique")));
0117   QCOMPARE(entry->field("nationality"), QLatin1String("Australie"));
0118   QCOMPARE(entry->field("studio"), QLatin1String("Cambridge Productions; Michael Edgley International; Snowy River Investment Pty. Ltd."));
0119   QCOMPARE(entry->field("running-time"), QLatin1String("102"));
0120   QCOMPARE(entry->field("audio-track"), QLatin1String("Dolby"));
0121   QCOMPARE(entry->field("aspect-ratio"), QLatin1String("2.35 : 1"));
0122 //  QCOMPARE(entry->field("color"), QLatin1String("Color"));
0123   QCOMPARE(entry->field("language"), QLatin1String("Anglais"));
0124   QCOMPARE(entry->field("director"), QLatin1String("George Miller"));
0125   QCOMPARE(entry->field("certification"), QLatin1String("PG (USA)"));
0126   QCOMPARE(set(entry->field("writer")), set(QLatin1String("Cul Cullen; A.B. 'Banjo' Paterson; John Dixon")));
0127   QStringList castList = Tellico::FieldFormat::splitTable(entry->field("cast"));
0128   QCOMPARE(castList.at(0), QLatin1String("Tom Burlinson::Jim Craig"));
0129   QCOMPARE(entry->field("imdb"), QLatin1String("https://www.imdb.com/title/tt0084296/"));
0130   QVERIFY(!entry->field("imdb-rating").isEmpty());
0131   QVERIFY(!entry->field("plot").isEmpty());
0132   QVERIFY(!entry->field("plot").contains(QStringLiteral("apos")));
0133   QVERIFY(!entry->field("cover").isEmpty());
0134   QVERIFY(!entry->field("cover").contains(QLatin1Char('/')));
0135 
0136   m_config.writeEntry("Lang", QStringLiteral("0")); // back to english
0137 }
0138 
0139 void ImdbFetcherTest::testAsterix() {
0140   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title, QStringLiteral("Astérix aux jeux olympiques"));
0141   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::IMDBFetcher(this));
0142   fetcher->readConfig(m_config);
0143 
0144   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0145 
0146   QCOMPARE(results.size(), 1);
0147 
0148   // the first entry had better be the right one
0149   Tellico::Data::EntryPtr entry = results.at(0);
0150 
0151   // title is returned in english
0152   QCOMPARE(entry->field("title"), QStringLiteral("Asterix at the Olympic Games"));
0153   QCOMPARE(entry->field("origtitle"), QString::fromUtf8("Astérix aux jeux olympiques"));
0154   QCOMPARE(set(entry, "director"), set(QString::fromUtf8("Thomas Langmann; Frédéric Forestier")));
0155   QCOMPARE(set(entry, "writer"), set(QString::fromUtf8("Franck Magnier; René Goscinny; Olivier Dazat; Alexandre Charlot; Thomas Langmann; Albert Uderzo")));
0156   QVERIFY(!entry->field("plot").isEmpty());
0157   QVERIFY(!entry->field("plot").contains('>'));
0158   QVERIFY(!entry->field("plot").contains("»"));
0159   QStringList altTitleList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("alttitle")));
0160   QVERIFY(altTitleList.contains(QString::fromUtf8("Asterix at the Olympic Games")));
0161   QVERIFY(altTitleList.contains(QString::fromUtf8("Astérix en los Juegos Olímpicos")));
0162   QVERIFY(altTitleList.contains(QStringLiteral("Asterix alle Olimpiadi")));
0163 }
0164 
0165 // https://bugs.kde.org/show_bug.cgi?id=249096
0166 void ImdbFetcherTest::testBodyDouble() {
0167   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title, QStringLiteral("Body Double"));
0168   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::IMDBFetcher(this));
0169 
0170   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0171 
0172   QCOMPARE(results.size(), 1);
0173 
0174   // the first entry had better be the right one
0175   Tellico::Data::EntryPtr entry = results.at(0);
0176 
0177   QCOMPARE(entry->field("title"), QStringLiteral("Body Double"));
0178   QCOMPARE(entry->field("director"), QStringLiteral("Brian De Palma"));
0179   QCOMPARE(set(entry, "writer"), set("Brian De Palma; Robert J. Avrech"));
0180   QCOMPARE(entry->field("producer"), QStringLiteral("Brian De Palma"));
0181 }
0182 
0183 // https://bugs.kde.org/show_bug.cgi?id=249096
0184 void ImdbFetcherTest::testMary() {
0185   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title, QStringLiteral("There's Something About Mary"));
0186   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::IMDBFetcher(this));
0187 
0188   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0189 
0190   QCOMPARE(results.size(), 1);
0191 
0192   // the first entry had better be the right one
0193   Tellico::Data::EntryPtr entry = results.at(0);
0194 
0195   QCOMPARE(set(entry, "director"), set("Peter Farrelly; Bobby Farrelly"));
0196   QCOMPARE(set(entry, "writer"), set("John J. Strauss; Ed Decter; Peter Farrelly; Bobby Farrelly"));
0197 }
0198 
0199 // https://bugs.kde.org/show_bug.cgi?id=262036
0200 // https://bugs.kde.org/show_bug.cgi?id=401894
0201 void ImdbFetcherTest::testOkunen() {
0202   // test bug 401894
0203   QLocale::setDefault(QLocale(QLocale::Italian, QLocale::Italy));
0204   m_config.writeEntry("Custom Fields", QStringLiteral("alttitle,imdb,imdb-rating"));
0205 
0206   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title, QStringLiteral("46-okunen no koi"));
0207   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::IMDBFetcher(this));
0208   fetcher->readConfig(m_config);
0209 
0210   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0211 
0212   QCOMPARE(results.size(), 1);
0213   Tellico::Data::EntryPtr entry = results.at(0);
0214 
0215   // if the settings included origtitle, then the title would be "Big Bang Love, Juvenile A"
0216   QCOMPARE(entry->field("title"), QStringLiteral("46-okunen no koi"));
0217   QCOMPARE(entry->field("origtitle"), QString());
0218   QCOMPARE(entry->field("year"), QStringLiteral("2006"));
0219   QCOMPARE(entry->field("genre"), QStringLiteral("Drama; Fantasy"));
0220   QCOMPARE(entry->field("director"), QStringLiteral("Takashi Miike"));
0221   // imdb rating is a volatile value, shouldn't be empty, shouldn't be 0
0222   QVERIFY(!entry->field("imdb-rating").isEmpty());
0223   QVERIFY(entry->field("imdb-rating") != QStringLiteral("0"));
0224   QCOMPARE(set(entry, "writer"), set("Ikki Kajiwara; Hisao Maki; Masa Nakamura"));
0225   QVERIFY(!entry->field("plot").isEmpty());
0226   QVERIFY(!entry->field("cover").isEmpty());
0227   QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/')));
0228   QStringList altTitleList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("alttitle")));
0229   QVERIFY(altTitleList.contains(QStringLiteral("Big Bang Love, Juvenile A")));
0230   // return the custom fields setting to what the other tests use
0231   m_config.writeEntry("Custom Fields", QStringLiteral("alttitle,imdb,imdb-rating,origtitle"));
0232 }
0233 
0234 // https://bugs.kde.org/show_bug.cgi?id=314113
0235 void ImdbFetcherTest::testFetchResultEncoding() {
0236   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title,
0237                                        QStringLiteral("jôbafuku onna harakiri"));
0238   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::IMDBFetcher(this));
0239 
0240   if(!hasNetwork()) {
0241     QSKIP("This test requires network access", SkipSingle);
0242     return;
0243   }
0244 
0245   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0246 
0247   QCOMPARE(results.size(), 1);
0248   Tellico::Data::EntryPtr entry = results.at(0);
0249   QVERIFY(entry);
0250 
0251   QCOMPARE(entry->title(), QString::fromUtf8("'Shitsurakuen': jôbafuku onna harakiri"));
0252 }
0253 
0254 // https://bugs.kde.org/show_bug.cgi?id=336765
0255 void ImdbFetcherTest::testBabel() {
0256   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title, QStringLiteral("Babel"));
0257   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::IMDBFetcher(this));
0258 
0259   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0260 
0261   QCOMPARE(results.size(), 1);
0262 
0263   // the first entry had better be the right one
0264   Tellico::Data::EntryPtr entry = results.at(0);
0265 
0266   QCOMPARE(entry->field("title"), QStringLiteral("Babel"));
0267   QCOMPARE(entry->field("year"), QStringLiteral("2006"));
0268   QCOMPARE(entry->field("director"), QString::fromUtf8("Alejandro G. Iñárritu"));
0269   QCOMPARE(set(entry, "writer"), set(QString::fromUtf8("Alejandro G. Iñárritu; Guillermo Arriaga")));
0270   QCOMPARE(set(entry, "producer"), set(QString::fromUtf8("Steve Golin; Alejandro G. Iñárritu; Jon Kilik; Ann Ruark; Corinne Golden Weber")));
0271 }
0272 
0273 void ImdbFetcherTest::testFirefly() {
0274   m_config.writeEntry("Custom Fields", QStringLiteral("imdb,episode"));
0275   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title, QStringLiteral("Firefly 2002"));
0276   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::IMDBFetcher(this));
0277   fetcher->readConfig(m_config);
0278 
0279   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0280 
0281   QCOMPARE(results.size(), 1);
0282 
0283   // the first entry had better be the right one
0284   Tellico::Data::EntryPtr entry = results.at(0);
0285 
0286   QCOMPARE(entry->field("title"), QStringLiteral("Firefly"));
0287   QCOMPARE(entry->field("year"), QStringLiteral("2002"));
0288   QCOMPARE(entry->field("producer"), QStringLiteral("Gareth Davies; Lisa Lassek; Brian Wankum; Ben Edlund"));
0289   QVERIFY(entry->field("director").startsWith(QStringLiteral("Joss Whedon; Vern Gillum; Tim Minear")));
0290   QVERIFY(entry->field("writer").startsWith(QStringLiteral("Joss Whedon; Cheryl Cain")));
0291   QCOMPARE(entry->field("composer"), QStringLiteral("Greg Edmonson"));
0292   QCOMPARE(set(entry->field("genre")), set(QStringLiteral("Adventure; Drama; Sci-Fi")));
0293   QVERIFY(entry->field("cast").startsWith(QStringLiteral("Nathan Fillion::Captain Malcolm 'Mal' Reynolds")));
0294   QVERIFY(!entry->field("cast").contains(QStringLiteral("episodes")));
0295   QStringList episodeList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("episode")));
0296   QVERIFY(!episodeList.isEmpty());
0297   QCOMPARE(episodeList.at(0), QStringLiteral("The Train Job::1::1"));
0298   QVERIFY(entry->field("plot").startsWith(QStringLiteral("Captain Malcolm")));
0299 }