Skip to content

Commit 038984d

Browse files
authored
Adapt to to The GamesDB API changes per 2026-02-17 (#224)
1 parent 9099b34 commit 038984d

4 files changed

Lines changed: 46 additions & 27 deletions

File tree

docs/CONFIGINI.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,13 @@ or
10561056
userCreds="<Client-ID>:<Client-Secret>"
10571057
```
10581058

1059+
or
1060+
1061+
```ini
1062+
[thegamesdb]
1063+
userCreds="<your-private-api-key-of-64chars>"
1064+
```
1065+
10591066
Default value: unset
10601067
Allowed in sections: `[<SCRAPER>]`
10611068

docs/SCRAPINGMODULES.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ I strongly recommend supporting them by contributing data to the database, or by
9696
- Website: _[www.thegamesdb.net](http://www.thegamesdb.net)_
9797
- Type: _File name search based_
9898
- User credential support: _Not required_
99-
- API request limit: _Limited to 3000 requests per IP per month_
99+
- API request limit: _Limited to 1000 requests per IP per month_
100100
- Thread limit: _None_
101101
- Platform support: _[Link to list](https://thegamesdb.net/list_platforms.php) or see `tgdb_platforms.json` sibling to your `config.ini`_
102102
- Media support: `backcover`, `cover`, `fanart`, `marquee`, `screenshot`, `wheel`
@@ -107,7 +107,7 @@ I strongly recommend supporting them by contributing data to the database, or by
107107

108108
For newer games there's no way around TheGames DB. It recently had a huge redesign and their database remains one of the best out there. I would recommend scraping your roms with `screenscraper` first, and then use `thegamesdb` to fill out the gaps in your cache.
109109

110-
There's a small caveat to this module, as it has a monthly request limit (see above) per IP per month. But this should be plenty for most people.
110+
There's a small caveat to this module, as it has a monthly request limit (see above) per IP per month. As per Feb 17th of 2026 TGDB have changed they API usage policy: You may have to register for your private API key to increase the above limits. Put your private API key then in the [`userCreds=`](CONFIGINI.md#usercreds) section of `[thegamesdb]`, or use the `-u` option when scraping with this module.
111111

112112
Their API is based on a file name search. This means that the returned results do have a chance of being faulty. Skyscraper does a lot internally to make sure accepted data is for the correct game. But it is impossible to ensure 100% correct results, so do keep that in mind when using it. Consider using the `--flags interactive` command line flag if you want complete control of the accepted entries.
113113

src/thegamesdb.cpp

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,9 @@ void TheGamesDb::getSearchResults(QList<GameEntry> &gameEntries,
6565
pIds.append(QString::number(p));
6666
}
6767
}
68-
69-
QString req =
70-
searchUrlPre +
71-
StrTools::unMagic(
72-
"187;161;217;126;172;149;202;122;163;197;163;219;162;171;203;197;"
73-
"139;151;215;173;122;206;161;162;200;216;217;123;124;215;200;170;"
74-
"171;132;158;155;215;120;149;169;140;164;122;154;178;174;160;172;"
75-
"157;131;210;161;203;137;159;117;205;166;162;139;171;169;210;163") +
76-
"&name=" + searchName + "&filter[platform]=" + pIds.join(",");
68+
QString k = getKey();
69+
QString req = searchUrlPre + k + "&name=" + searchName +
70+
"&filter[platform]=" + pIds.join(",");
7771
netComm->request(req);
7872
q.exec();
7973
data = netComm->getData();
@@ -84,14 +78,25 @@ void TheGamesDb::getSearchResults(QList<GameEntry> &gameEntries,
8478
return;
8579
}
8680

87-
reqRemaining = jsonDoc.object()["remaining_monthly_allowance"].toInt();
81+
QString status = jsonDoc.object()["status"].toString();
82+
if (status != "Success") {
83+
QString code = jsonDoc.object()["code"].toString();
84+
if (code != "200") {
85+
printf("\033[1;31mServer response HTTP %s: %s\033[0m\n",
86+
code.toStdString().c_str(), status.toStdString().c_str());
87+
}
88+
return;
89+
}
90+
QJsonObject obj = jsonDoc.object();
91+
reqRemaining = obj["extra_allowance"].toInt();
92+
if (reqRemaining <= 0) {
93+
reqRemaining = obj["remaining_monthly_allowance"].toInt();
94+
}
8895
if (reqRemaining <= 0)
8996
printf("\033[1;31mYou've reached TheGamesdDb's request limit for this "
90-
"month.\033[0m\n");
97+
"month with %s API key.\033[0m\n",
98+
config->userCreds.isEmpty() ? "the public" : "your private");
9199

92-
if (jsonDoc.object()["status"].toString() != "Success") {
93-
return;
94-
}
95100
if (jsonDoc.object()["data"].toObject()["count"].toInt() < 1) {
96101
return;
97102
}
@@ -109,17 +114,11 @@ void TheGamesDb::getSearchResults(QList<GameEntry> &gameEntries,
109114
GameEntry game;
110115

111116
game.id = QString::number(jsonGame["id"].toInt());
112-
game.url =
113-
QString("%1/Games/ByGameID?id=%2&apikey=%3&fields=%4")
114-
.arg(baseUrl)
115-
.arg(game.id)
116-
.arg(QString(StrTools::unMagic(
117-
"187;161;217;126;172;149;202;122;163;197;163;219;162;"
118-
"171;203;197;139;151;215;173;122;206;161;162;200;216;"
119-
"217;123;124;215;200;170;171;132;158;155;215;120;149;"
120-
"169;140;164;122;154;178;174;160;172;157;131;210;161;"
121-
"203;137;159;117;205;166;162;139;171;169;210;163")))
122-
.arg(fields.join(","));
117+
game.url = QString("%1/Games/ByGameID?id=%2&apikey=%3&fields=%4")
118+
.arg(baseUrl)
119+
.arg(game.id)
120+
.arg(k)
121+
.arg(fields.join(","));
123122

124123
game.title = jsonGame["game_title"].toString();
125124
// Remove anything at the end with a parentheses. 'thegamesdb' has a
@@ -301,4 +300,16 @@ void TheGamesDb::loadMaps() {
301300

302301
QVector<int> TheGamesDb::getPlatformId(const QString platform) {
303302
return Platform::get().getPlatformIdOnScraper(platform, config->scraper);
303+
}
304+
305+
QString TheGamesDb::getKey() {
306+
QString k = config->userCreds;
307+
if (k.isEmpty()) {
308+
k = StrTools::unMagic(
309+
"189;159;218;132;218;153;203;170;166;155;168;177;211;217;203;153;"
310+
"137;152;167;175;126;161;209;162;150;165;216;128;173;168;149;169;"
311+
"213;137;203;161;163;170;196;215;182;168;118;156;132;171;202;165;"
312+
"153;177;168;208;155;134;212;166;164;163;161;184;168;163;160;211");
313+
}
314+
return k;
304315
}

src/thegamesdb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class TheGamesDb : public AbstractScraper {
5656
void getFanart(GameEntry &game) override;
5757
void getBackcover(GameEntry &game) override;
5858
QVector<int> getPlatformId(const QString platform) override;
59+
QString getKey();
5960

6061
QString gfxUrl;
6162
QJsonDocument jsonDoc;

0 commit comments

Comments
 (0)