boxart: skip invalid disks. fix disk id dash issue. save found status
This commit is contained in:
parent
5259aa20e6
commit
3915c55251
|
@ -22,6 +22,7 @@
|
|||
#include "imgread/common.h"
|
||||
#include "stdclass.h"
|
||||
#include "oslib/oslib.h"
|
||||
#include <cctype>
|
||||
|
||||
#define APIKEY "3fcc5e726a129924972be97abfd577ac5311f8f12398a9d9bcb5a377d4656fa8"
|
||||
|
||||
|
@ -230,12 +231,21 @@ void TheGamesDb::scrape(GameBoxart& item)
|
|||
throw std::runtime_error("");
|
||||
blackoutPeriod = 0.0;
|
||||
|
||||
item.found = false;
|
||||
int platform = getGamePlatform(item.gamePath.c_str());
|
||||
std::string gameName;
|
||||
std::string uniqueId;
|
||||
if (platform == DC_PLATFORM_DREAMCAST)
|
||||
{
|
||||
Disc *disc = OpenDisc(item.gamePath.c_str());
|
||||
Disc *disc;
|
||||
try {
|
||||
disc = OpenDisc(item.gamePath.c_str());
|
||||
} catch (const std::exception& e) {
|
||||
WARN_LOG(COMMON, "Can't open disk %s: %s", item.gamePath.c_str(), e.what());
|
||||
// No need to retry if the disk is invalid/corrupted
|
||||
item.scraped = true;
|
||||
return;
|
||||
}
|
||||
|
||||
u32 base_fad;
|
||||
if (disc->type == GdRom) {
|
||||
|
@ -273,6 +283,15 @@ void TheGamesDb::scrape(GameBoxart& item)
|
|||
gameName = item.name;
|
||||
}
|
||||
|
||||
if (!uniqueId.empty())
|
||||
{
|
||||
if (uniqueId.find('-') == std::string::npos)
|
||||
{
|
||||
// add a dash between letters and numbers
|
||||
auto pos = uniqueId.find_first_of("0123456789");
|
||||
if (pos != 0 && pos != std::string::npos)
|
||||
uniqueId = uniqueId.substr(0, pos) + "-" + uniqueId.substr(pos);
|
||||
}
|
||||
std::string url = makeUrl("Games/ByGameUniqueID") + "&fields=overview&include=boxart&filter%5Bplatform%5D=";
|
||||
if (platform == DC_PLATFORM_DREAMCAST)
|
||||
url += std::to_string(dreamcastPlatformId);
|
||||
|
@ -280,15 +299,17 @@ void TheGamesDb::scrape(GameBoxart& item)
|
|||
url += std::to_string(arcadePlatformId);
|
||||
url += "&uid=" + http::urlEncode(uniqueId);
|
||||
|
||||
if (uniqueId.empty() || !fetchGameInfo(item, url))
|
||||
item.found = fetchGameInfo(item, url);
|
||||
}
|
||||
if (!item.found)
|
||||
{
|
||||
url = makeUrl("Games/ByGameName") + "&fields=overview&include=boxart&filter%5Bplatform%5D=";
|
||||
std::string url = makeUrl("Games/ByGameName") + "&fields=overview&include=boxart&filter%5Bplatform%5D=";
|
||||
if (platform == DC_PLATFORM_DREAMCAST)
|
||||
url += std::to_string(dreamcastPlatformId);
|
||||
else
|
||||
url += std::to_string(arcadePlatformId);
|
||||
url += "&name=" + http::urlEncode(gameName);
|
||||
fetchGameInfo(item, url);
|
||||
item.found = fetchGameInfo(item, url);
|
||||
}
|
||||
item.scraped = true;
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ struct GameBoxart
|
|||
std::string boxartPath;
|
||||
|
||||
bool scraped = false;
|
||||
bool found = false;
|
||||
|
||||
enum Region { JAPAN = 1, USA = 2, EUROPE = 4 };
|
||||
|
||||
|
@ -57,6 +58,7 @@ struct GameBoxart
|
|||
{ "fanart_path", fanartPath },
|
||||
{ "boxart_path", boxartPath },
|
||||
{ "scraped", scraped },
|
||||
{ "found", found },
|
||||
};
|
||||
return j;
|
||||
}
|
||||
|
@ -65,10 +67,14 @@ struct GameBoxart
|
|||
static void loadProperty(T& i, const json& j, const std::string& propName)
|
||||
{
|
||||
try {
|
||||
// asan error if missing contains(). json bug?
|
||||
if (j.contains(propName)) {
|
||||
i = j[propName].get<T>();
|
||||
} catch (const json::exception& e) {
|
||||
i = T();
|
||||
return;
|
||||
}
|
||||
} catch (const json::exception& e) {
|
||||
}
|
||||
i = T();
|
||||
}
|
||||
|
||||
GameBoxart() = default;
|
||||
|
@ -85,6 +91,7 @@ struct GameBoxart
|
|||
loadProperty(fanartPath, j, "fanart_path");
|
||||
loadProperty(boxartPath, j, "boxart_path");
|
||||
loadProperty(scraped, j, "scraped");
|
||||
loadProperty(found, j, "found");
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue