File indexing completed on 2024-05-12 05:10:01
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 "../images/imageinfo.h" 0035 #include "../fieldformat.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 system locale every time 0056 QLocale::setDefault(QLocale::system()); 0057 } 0058 0059 void ImdbFetcherTest::testSnowyRiver() { 0060 m_config.writeEntry("Image Size", 1); // small 0061 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title, QStringLiteral("The Man From Snowy River")); 0062 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::IMDBFetcher(this)); 0063 fetcher->readConfig(m_config); 0064 0065 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0066 0067 QCOMPARE(results.size(), 1); 0068 0069 // the first entry had better be the right one 0070 Tellico::Data::EntryPtr entry = results.at(0); 0071 0072 QCOMPARE(entry->field("title"), QStringLiteral("The Man from Snowy River")); 0073 QCOMPARE(entry->field("year"), QStringLiteral("1982")); 0074 QCOMPARE(set(entry, "genre"), set("Adventure; Drama; Romance; Western")); 0075 QCOMPARE(entry->field("nationality"), QStringLiteral("Australia")); 0076 QCOMPARE(set(entry, "studio"), set("Cambridge Productions; Michael Edgley International; Snowy River Investment Pty. Ltd.")); 0077 QCOMPARE(entry->field("running-time"), QStringLiteral("102")); 0078 QCOMPARE(entry->field("audio-track"), QStringLiteral("Dolby")); 0079 QCOMPARE(entry->field("aspect-ratio"), QStringLiteral("2.35 : 1")); 0080 QCOMPARE(entry->field("color"), QStringLiteral("Color")); 0081 QCOMPARE(entry->field("language"), QStringLiteral("English")); 0082 QCOMPARE(entry->field("certification"), QStringLiteral("PG (USA)")); 0083 QCOMPARE(entry->field("director"), QStringLiteral("George Miller")); 0084 QCOMPARE(set(entry->field("producer")), set(QStringLiteral("Geoff Burrowes; Michael Edgley; Simon Wincer"))); 0085 QCOMPARE(entry->field("composer"), QStringLiteral("Bruce Rowland")); 0086 QCOMPARE(set(entry, "writer"), set("Cul Cullen; A.B. 'Banjo' Paterson;John Dixon")); 0087 QStringList castList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("cast"))); 0088 QVERIFY(!castList.isEmpty()); 0089 QCOMPARE(castList.at(0), QStringLiteral("Tom Burlinson::Jim Craig")); 0090 QCOMPARE(entry->field("imdb"), QStringLiteral("https://www.imdb.com/title/tt0084296/")); 0091 QVERIFY(!entry->field("imdb-rating").isEmpty()); 0092 QVERIFY(!entry->field("plot").isEmpty()); 0093 QVERIFY(!entry->field("plot").contains('>')); 0094 QVERIFY(!entry->field("cover").isEmpty()); 0095 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0096 auto imageInfo = Tellico::ImageFactory::imageInfo(entry->field("cover")); 0097 QVERIFY(imageInfo.height() <= 256); 0098 QVERIFY(imageInfo.width() <= 256); 0099 QStringList altTitleList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("alttitle"))); 0100 QVERIFY(altTitleList.contains(QStringLiteral("Herencia de un valiente"))); 0101 QVERIFY(!entry->field("alttitle").contains(QStringLiteral("See more"))); 0102 } 0103 0104 void ImdbFetcherTest::testSnowyRiverFr() { 0105 QLocale::setDefault(QLocale(QLocale::French, QLocale::France)); 0106 0107 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title, "The Man From Snowy River"); 0108 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::IMDBFetcher(this)); 0109 fetcher->readConfig(m_config); 0110 0111 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0112 0113 QCOMPARE(results.size(), 1); 0114 0115 // the first entry had better be the right one 0116 Tellico::Data::EntryPtr entry = results.at(0); 0117 0118 QCOMPARE(entry->field("title"), QString::fromUtf8("L'homme de la rivière d'argent")); 0119 QCOMPARE(entry->field("year"), QLatin1String("1982")); 0120 // with GraphQL, genres still in english 0121 // QCOMPARE(set(entry->field("genre")), set(QLatin1String("Aventure; Drame; Romantique"))); 0122 // QCOMPARE(entry->field("nationality"), QLatin1String("Australie")); 0123 QCOMPARE(entry->field("studio"), QLatin1String("Cambridge Productions; Michael Edgley International; Snowy River Investment Pty. Ltd.")); 0124 QCOMPARE(entry->field("running-time"), QLatin1String("102")); 0125 QCOMPARE(entry->field("audio-track"), QLatin1String("Dolby")); 0126 QCOMPARE(entry->field("aspect-ratio"), QLatin1String("2.35 : 1")); 0127 QCOMPARE(entry->field("color"), QLatin1String("Color")); 0128 // QCOMPARE(entry->field("language"), QLatin1String("Anglais")); 0129 QCOMPARE(entry->field("director"), QLatin1String("George Miller")); 0130 QCOMPARE(entry->field("certification"), QLatin1String("PG (USA)")); 0131 QCOMPARE(set(entry->field("writer")), set(QLatin1String("Cul Cullen; A.B. 'Banjo' Paterson; John Dixon"))); 0132 QStringList castList = Tellico::FieldFormat::splitTable(entry->field("cast")); 0133 QCOMPARE(castList.at(0), QLatin1String("Tom Burlinson::Jim Craig")); 0134 QCOMPARE(entry->field("imdb"), QLatin1String("https://www.imdb.com/title/tt0084296/")); 0135 QVERIFY(!entry->field("imdb-rating").isEmpty()); 0136 QVERIFY(!entry->field("plot").isEmpty()); 0137 QVERIFY(!entry->field("plot").contains(QStringLiteral("apos"))); 0138 QVERIFY(!entry->field("cover").isEmpty()); 0139 QVERIFY(!entry->field("cover").contains(QLatin1Char('/'))); 0140 } 0141 0142 void ImdbFetcherTest::testPacteDesLoupsEn() { 0143 m_config.writeEntry("System Locale", false); 0144 m_config.writeEntry("Custom Locale", "en_US"); 0145 QLocale::setDefault(QLocale(QLocale::French, QLocale::France)); 0146 0147 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title, "Pacte des Loups"); 0148 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::IMDBFetcher(this)); 0149 fetcher->readConfig(m_config); 0150 0151 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0152 0153 QCOMPARE(results.size(), 1); 0154 0155 // the first entry had better be the right one 0156 Tellico::Data::EntryPtr entry = results.at(0); 0157 0158 QCOMPARE(entry->field("title"), QLatin1String("Brotherhood of the Wolf")); 0159 } 0160 0161 void ImdbFetcherTest::testAsterix() { 0162 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title, QStringLiteral("Astérix aux jeux olympiques")); 0163 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::IMDBFetcher(this)); 0164 fetcher->readConfig(m_config); 0165 0166 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0167 0168 QCOMPARE(results.size(), 1); 0169 0170 // the first entry had better be the right one 0171 Tellico::Data::EntryPtr entry = results.at(0); 0172 0173 // title is returned in english 0174 QCOMPARE(entry->field("title"), QStringLiteral("Asterix at the Olympic Games")); 0175 QCOMPARE(entry->field("origtitle"), QString::fromUtf8("Astérix aux jeux olympiques")); 0176 QCOMPARE(set(entry, "director"), set(QString::fromUtf8("Thomas Langmann; Frédéric Forestier"))); 0177 QCOMPARE(set(entry, "writer"), set(QString::fromUtf8("Franck Magnier; René Goscinny; Olivier Dazat; Alexandre Charlot; Thomas Langmann; Albert Uderzo"))); 0178 QVERIFY(!entry->field("plot").isEmpty()); 0179 QVERIFY(!entry->field("plot").contains('>')); 0180 QVERIFY(!entry->field("plot").contains("»")); 0181 QStringList altTitleList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("alttitle"))); 0182 QVERIFY(altTitleList.contains(QString::fromUtf8("Asterix at the Olympic Games"))); 0183 QVERIFY(altTitleList.contains(QString::fromUtf8("Astérix en los Juegos Olímpicos"))); 0184 QVERIFY(altTitleList.contains(QStringLiteral("Asterix alle Olimpiadi"))); 0185 } 0186 0187 // https://bugs.kde.org/show_bug.cgi?id=249096 0188 void ImdbFetcherTest::testBodyDouble() { 0189 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title, QStringLiteral("Body Double")); 0190 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::IMDBFetcher(this)); 0191 0192 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0193 0194 QCOMPARE(results.size(), 1); 0195 0196 // the first entry had better be the right one 0197 Tellico::Data::EntryPtr entry = results.at(0); 0198 0199 QCOMPARE(entry->field("title"), QStringLiteral("Body Double")); 0200 QCOMPARE(entry->field("director"), QStringLiteral("Brian De Palma")); 0201 QCOMPARE(set(entry, "writer"), set("Brian De Palma; Robert J. Avrech")); 0202 QCOMPARE(entry->field("producer"), QStringLiteral("Brian De Palma; Howard Gottfried")); 0203 } 0204 0205 // https://bugs.kde.org/show_bug.cgi?id=249096 0206 void ImdbFetcherTest::testMary() { 0207 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title, QStringLiteral("There's Something About Mary")); 0208 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::IMDBFetcher(this)); 0209 0210 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0211 0212 QCOMPARE(results.size(), 1); 0213 0214 // the first entry had better be the right one 0215 Tellico::Data::EntryPtr entry = results.at(0); 0216 0217 QCOMPARE(set(entry, "director"), set("Peter Farrelly; Bobby Farrelly")); 0218 QCOMPARE(set(entry, "writer"), set("John J. Strauss; Ed Decter; Peter Farrelly; Bobby Farrelly")); 0219 } 0220 0221 // https://bugs.kde.org/show_bug.cgi?id=262036 0222 // https://bugs.kde.org/show_bug.cgi?id=401894 0223 void ImdbFetcherTest::testOkunen() { 0224 // test bug 401894 0225 QLocale::setDefault(QLocale(QLocale::Italian, QLocale::Italy)); 0226 m_config.writeEntry("Custom Fields", QStringLiteral("alttitle,imdb,imdb-rating")); 0227 0228 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title, QStringLiteral("46-okunen no koi")); 0229 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::IMDBFetcher(this)); 0230 fetcher->readConfig(m_config); 0231 0232 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0233 0234 QCOMPARE(results.size(), 1); 0235 Tellico::Data::EntryPtr entry = results.at(0); 0236 0237 // if the settings included origtitle, then the title would be "Big Bang Love, Juvenile A" 0238 QCOMPARE(entry->field("title"), QStringLiteral("46-okunen no koi")); 0239 QCOMPARE(entry->field("origtitle"), QString()); 0240 QCOMPARE(entry->field("year"), QStringLiteral("2006")); 0241 QCOMPARE(entry->field("genre"), QStringLiteral("Drama; Fantasy")); 0242 QCOMPARE(entry->field("director"), QStringLiteral("Takashi Miike")); 0243 // imdb rating is a volatile value, shouldn't be empty, shouldn't be 0 0244 QVERIFY(!entry->field("imdb-rating").isEmpty()); 0245 QVERIFY(entry->field("imdb-rating") != QStringLiteral("0")); 0246 QCOMPARE(set(entry, "writer"), set("Ikki Kajiwara; Hisao Maki; Masa Nakamura")); 0247 QVERIFY(!entry->field("plot").isEmpty()); 0248 QVERIFY(!entry->field("cover").isEmpty()); 0249 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0250 QStringList altTitleList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("alttitle"))); 0251 QVERIFY(altTitleList.contains(QStringLiteral("Big Bang Love, Juvenile A"))); 0252 // return the custom fields setting to what the other tests use 0253 m_config.writeEntry("Custom Fields", QStringLiteral("alttitle,imdb,imdb-rating,origtitle")); 0254 } 0255 0256 // https://bugs.kde.org/show_bug.cgi?id=314113 0257 void ImdbFetcherTest::testFetchResultEncoding() { 0258 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title, 0259 QStringLiteral("jôbafuku onna harakiri")); 0260 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::IMDBFetcher(this)); 0261 0262 if(!hasNetwork()) { 0263 QSKIP("This test requires network access", SkipSingle); 0264 return; 0265 } 0266 0267 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0268 0269 QCOMPARE(results.size(), 1); 0270 Tellico::Data::EntryPtr entry = results.at(0); 0271 QVERIFY(entry); 0272 0273 QCOMPARE(entry->title(), QString::fromUtf8("'Shitsurakuen': Jôbafuku Onna Harakiri")); 0274 } 0275 0276 // https://bugs.kde.org/show_bug.cgi?id=336765 0277 void ImdbFetcherTest::testBabel() { 0278 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title, QStringLiteral("Babel")); 0279 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::IMDBFetcher(this)); 0280 0281 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0282 0283 QCOMPARE(results.size(), 1); 0284 0285 // the first entry had better be the right one 0286 Tellico::Data::EntryPtr entry = results.at(0); 0287 0288 QCOMPARE(entry->field("title"), QStringLiteral("Babel")); 0289 QCOMPARE(entry->field("year"), QStringLiteral("2006")); 0290 QCOMPARE(entry->field("director"), QString::fromUtf8("Alejandro G. Iñárritu")); 0291 QCOMPARE(set(entry, "writer"), set(QString::fromUtf8("Alejandro G. Iñárritu; Guillermo Arriaga"))); 0292 QCOMPARE(set(entry, "producer"), set(QString::fromUtf8("Steve Golin; Alejandro G. Iñárritu; Jimmy Abounouom; Jon Kilik; Kay Ueda; Norihisa Harada; Ann Ruark; Corinne Golden Weber; Tita Lombardo"))); 0293 } 0294 0295 void ImdbFetcherTest::testFirefly() { 0296 m_config.writeEntry("Custom Fields", QStringLiteral("imdb,episode")); 0297 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title, QStringLiteral("firefly 2002")); 0298 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::IMDBFetcher(this)); 0299 fetcher->readConfig(m_config); 0300 0301 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0302 0303 QCOMPARE(results.size(), 1); 0304 0305 // the first entry had better be the right one 0306 Tellico::Data::EntryPtr entry = results.at(0); 0307 0308 QCOMPARE(entry->field("title"), QStringLiteral("Firefly")); 0309 QCOMPARE(entry->field("year"), QStringLiteral("2002")); 0310 QCOMPARE(set(entry->field("producer")), set(QStringLiteral("Gareth Davies; Lisa Lassek; Brian Wankum; Tim Minear; Joss Whedon"))); 0311 QVERIFY(entry->field("director").contains(QStringLiteral("Joss Whedon"))); 0312 QVERIFY(entry->field("director").contains(QStringLiteral("Tim Minear"))); 0313 QVERIFY(entry->field("writer").contains(QStringLiteral("Joss Whedon"))); 0314 QVERIFY(entry->field("writer").contains(QStringLiteral("Cheryl Cain"))); 0315 QCOMPARE(entry->field("composer"), QStringLiteral("Greg Edmonson")); 0316 QCOMPARE(set(entry->field("genre")), set(QStringLiteral("Adventure; Drama; Sci-Fi"))); 0317 QVERIFY(entry->field("cast").startsWith(QStringLiteral("Nathan Fillion::Captain Malcolm 'Mal' Reynolds"))); 0318 QVERIFY(!entry->field("cast").contains(QStringLiteral("episodes"))); 0319 QStringList episodeList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("episode"))); 0320 QVERIFY(!episodeList.isEmpty()); 0321 if(!episodeList.isEmpty()) QCOMPARE(episodeList.at(0), QStringLiteral("The Train Job::1::1")); 0322 QVERIFY(entry->field("plot").startsWith(QStringLiteral("Five hundred"))); 0323 } 0324 0325 void ImdbFetcherTest::testUpdate() { 0326 Tellico::Data::CollPtr coll(new Tellico::Data::VideoCollection(true)); 0327 coll->addField(Tellico::Data::Field::createDefaultField(Tellico::Data::Field::ImdbField)); 0328 Tellico::Data::EntryPtr emptyEntry(new Tellico::Data::Entry(coll)); 0329 emptyEntry->setField(QLatin1String("imdb"), QStringLiteral("https://www.imdb.com/title/tt0084296/")); 0330 0331 m_config.writeEntry("Custom Fields", QStringLiteral("imdb,episode")); 0332 Tellico::Fetch::IMDBFetcher fetcher(this); 0333 fetcher.readConfig(m_config); 0334 auto request = fetcher.updateRequest(emptyEntry); 0335 request.setCollectionType(coll->type()); 0336 0337 Tellico::Data::EntryList results = DO_FETCH1(&fetcher, request, 1); 0338 QCOMPARE(results.size(), 1); 0339 0340 Tellico::Data::EntryPtr entry = results.at(0); 0341 QCOMPARE(entry->field("title"), QStringLiteral("The Man from Snowy River")); 0342 QCOMPARE(entry->field("year"), QStringLiteral("1982")); 0343 QCOMPARE(entry->field("imdb"), QStringLiteral("https://www.imdb.com/title/tt0084296/")); 0344 }