Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Office
Tellico
Commits
dbe48745
Commit
dbe48745
authored
Mar 23, 2022
by
Robby Stephenson
Browse files
Add screenshot for MobyGames source
parent
72312324
Pipeline
#154322
passed with stage
in 4 minutes and 2 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
ChangeLog
View file @
dbe48745
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.
...
...
src/fetch/mobygamesfetcher.cpp
View file @
dbe48745
...
...
@@ -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
;
}
...
...
src/fetch/thegamesdbfetcher.cpp
View file @
dbe48745
...
...
@@ -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"
));
...
...
src/field.cpp
View file @
dbe48745
...
...
@@ -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
;
...
...
src/field.h
View file @
dbe48745
...
...
@@ -318,7 +318,8 @@ public:
IsbnField
,
PegiField
,
ImdbField
,
EpisodeField
EpisodeField
,
ScreenshotField
};
static
FieldPtr
createDefaultField
(
DefaultField
field
);
...
...
src/tests/mobygamesfetchertest.cpp
View file @
dbe48745
...
...
@@ -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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment