Commit dbe48745 authored by Robby Stephenson's avatar Robby Stephenson
Browse files

Add screenshot for MobyGames source

parent 72312324
Pipeline #154322 passed with stage
in 4 minutes and 2 seconds
2022-03-23 Robby Stephenson <robby@periapsis.org>
* Added screenshot field for MobyGames source.
2022-03-22 Robby Stephenson <robby@periapsis.org>
* Added screenshot field for TheGamesDB source.
......
......@@ -348,6 +348,47 @@ Tellico::Data::EntryPtr MobyGamesFetcher::fetchEntryHook(uint uid_) {
entry->setField(QStringLiteral("cover"), id);
}
const QString screenshot = QStringLiteral("screenshot");
if(optionalFields().contains(screenshot)) {
if(!entry->collection()->hasField(screenshot)) {
entry->collection()->addField(Data::Field::createDefaultField(Data::Field::ScreenshotField));
}
u = QUrl(QString::fromLatin1(MOBYGAMES_API_URL));
u.setPath(u.path() + QStringLiteral("/games/%1/platforms/%2/screenshots")
.arg(entry->field(QStringLiteral("moby-id")),
entry->field(QStringLiteral("platform-id"))));
u.setQuery(q);
markTime();
job = KIO::storedGet(u, KIO::NoReload, KIO::HideProgressInfo);
KJobWidgets::setWindow(job, GUI::Proxy::widget());
if(!job->exec()) {
myDebug() << job->errorString() << u;
return entry;
}
#if 0
myWarning() << "Remove screenshots debug from mobygamesfetcher.cpp";
QFile file3(QStringLiteral("/tmp/moby-screenshots.json"));
if(file3.open(QIODevice::WriteOnly)) {
QTextStream t(&file3);
t.setCodec("UTF-8");
t << job->data();
}
file3.close();
#endif
QString screenshotUrl;
doc = QJsonDocument::fromJson(job->data());
map = doc.object().toVariantMap();
auto list = map.value(QStringLiteral("screenshots")).toList();
if(!list.isEmpty()) {
screenshotUrl = mapValue(list.at(0).toMap(), "image");
}
if(!screenshotUrl.isEmpty()) {
// myDebug() << screenshotUrl;
const QString id = ImageFactory::addImage(QUrl::fromUserInput(screenshotUrl), true /* quiet */);
entry->setField(screenshot, id);
}
}
// clear the placeholder fields
entry->setField(QStringLiteral("moby-id"), QString());
entry->setField(QStringLiteral("platform-id"), QString());
......@@ -595,6 +636,7 @@ Tellico::StringHash MobyGamesFetcher::allOptionalFields() {
StringHash hash;
hash[QStringLiteral("pegi")] = i18n("PEGI Rating");
hash[QStringLiteral("mobygames")] = i18n("MobyGames Link");
hash[QStringLiteral("screenshot")] = i18n("Screenshot");
return hash;
}
......
......@@ -179,8 +179,7 @@ Tellico::Data::EntryPtr TheGamesDBFetcher::fetchEntryHook(uint uid_) {
const QString screenshot = QStringLiteral("screenshot");
if(optionalFields().contains(screenshot)) {
if(!entry->collection()->hasField(screenshot)) {
Data::FieldPtr field(new Data::Field(screenshot, i18n("Screenshot"), Data::Field::Image));
entry->collection()->addField(field);
entry->collection()->addField(Data::Field::createDefaultField(Data::Field::ScreenshotField));
}
QUrl u(QString::fromLatin1(THEGAMESDB_API_URL));
u.setPath(QLatin1String("/v") + QLatin1String(THEGAMESDB_API_VERSION) + QLatin1String("/Games/Images"));
......
......@@ -339,6 +339,9 @@ Tellico::Data::FieldPtr Field::createDefaultField(DefaultField fieldEnum) {
field->setProperty(QStringLiteral("column2"), i18nc("TV Season", "Season"));
field->setProperty(QStringLiteral("column3"), i18nc("TV Episode", "Episode"));
break;
case ScreenshotField:
field = new Field(QStringLiteral("screenshot"), i18n("Screenshot"), Field::Image);
break;
}
Q_ASSERT(field);
return field;
......
......@@ -318,7 +318,8 @@ public:
IsbnField,
PegiField,
ImdbField,
EpisodeField
EpisodeField,
ScreenshotField
};
static FieldPtr createDefaultField(DefaultField field);
......
......@@ -92,6 +92,8 @@ void MobyGamesFetcherTest::testTitle() {
QVERIFY(!entry->field(QStringLiteral("description")).isEmpty());
QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty());
QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/')));
QVERIFY(!entry->field(QStringLiteral("screenshot")).isEmpty());
QVERIFY(!entry->field(QStringLiteral("screenshot")).contains(QLatin1Char('/')));
}
// same search, except to include platform name in search
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment