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 "imgread/common.h"
|
||||||
#include "stdclass.h"
|
#include "stdclass.h"
|
||||||
#include "oslib/oslib.h"
|
#include "oslib/oslib.h"
|
||||||
|
#include <cctype>
|
||||||
|
|
||||||
#define APIKEY "3fcc5e726a129924972be97abfd577ac5311f8f12398a9d9bcb5a377d4656fa8"
|
#define APIKEY "3fcc5e726a129924972be97abfd577ac5311f8f12398a9d9bcb5a377d4656fa8"
|
||||||
|
|
||||||
|
@ -230,12 +231,21 @@ void TheGamesDb::scrape(GameBoxart& item)
|
||||||
throw std::runtime_error("");
|
throw std::runtime_error("");
|
||||||
blackoutPeriod = 0.0;
|
blackoutPeriod = 0.0;
|
||||||
|
|
||||||
|
item.found = false;
|
||||||
int platform = getGamePlatform(item.gamePath.c_str());
|
int platform = getGamePlatform(item.gamePath.c_str());
|
||||||
std::string gameName;
|
std::string gameName;
|
||||||
std::string uniqueId;
|
std::string uniqueId;
|
||||||
if (platform == DC_PLATFORM_DREAMCAST)
|
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;
|
u32 base_fad;
|
||||||
if (disc->type == GdRom) {
|
if (disc->type == GdRom) {
|
||||||
|
@ -273,22 +283,33 @@ void TheGamesDb::scrape(GameBoxart& item)
|
||||||
gameName = item.name;
|
gameName = item.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string url = makeUrl("Games/ByGameUniqueID") + "&fields=overview&include=boxart&filter%5Bplatform%5D=";
|
if (!uniqueId.empty())
|
||||||
if (platform == DC_PLATFORM_DREAMCAST)
|
|
||||||
url += std::to_string(dreamcastPlatformId);
|
|
||||||
else
|
|
||||||
url += std::to_string(arcadePlatformId);
|
|
||||||
url += "&uid=" + http::urlEncode(uniqueId);
|
|
||||||
|
|
||||||
if (uniqueId.empty() || !fetchGameInfo(item, url))
|
|
||||||
{
|
{
|
||||||
url = makeUrl("Games/ByGameName") + "&fields=overview&include=boxart&filter%5Bplatform%5D=";
|
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);
|
||||||
|
else
|
||||||
|
url += std::to_string(arcadePlatformId);
|
||||||
|
url += "&uid=" + http::urlEncode(uniqueId);
|
||||||
|
|
||||||
|
item.found = fetchGameInfo(item, url);
|
||||||
|
}
|
||||||
|
if (!item.found)
|
||||||
|
{
|
||||||
|
std::string url = makeUrl("Games/ByGameName") + "&fields=overview&include=boxart&filter%5Bplatform%5D=";
|
||||||
if (platform == DC_PLATFORM_DREAMCAST)
|
if (platform == DC_PLATFORM_DREAMCAST)
|
||||||
url += std::to_string(dreamcastPlatformId);
|
url += std::to_string(dreamcastPlatformId);
|
||||||
else
|
else
|
||||||
url += std::to_string(arcadePlatformId);
|
url += std::to_string(arcadePlatformId);
|
||||||
url += "&name=" + http::urlEncode(gameName);
|
url += "&name=" + http::urlEncode(gameName);
|
||||||
fetchGameInfo(item, url);
|
item.found = fetchGameInfo(item, url);
|
||||||
}
|
}
|
||||||
item.scraped = true;
|
item.scraped = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ struct GameBoxart
|
||||||
std::string boxartPath;
|
std::string boxartPath;
|
||||||
|
|
||||||
bool scraped = false;
|
bool scraped = false;
|
||||||
|
bool found = false;
|
||||||
|
|
||||||
enum Region { JAPAN = 1, USA = 2, EUROPE = 4 };
|
enum Region { JAPAN = 1, USA = 2, EUROPE = 4 };
|
||||||
|
|
||||||
|
@ -57,6 +58,7 @@ struct GameBoxart
|
||||||
{ "fanart_path", fanartPath },
|
{ "fanart_path", fanartPath },
|
||||||
{ "boxart_path", boxartPath },
|
{ "boxart_path", boxartPath },
|
||||||
{ "scraped", scraped },
|
{ "scraped", scraped },
|
||||||
|
{ "found", found },
|
||||||
};
|
};
|
||||||
return j;
|
return j;
|
||||||
}
|
}
|
||||||
|
@ -65,10 +67,14 @@ struct GameBoxart
|
||||||
static void loadProperty(T& i, const json& j, const std::string& propName)
|
static void loadProperty(T& i, const json& j, const std::string& propName)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
i = j[propName].get<T>();
|
// asan error if missing contains(). json bug?
|
||||||
|
if (j.contains(propName)) {
|
||||||
|
i = j[propName].get<T>();
|
||||||
|
return;
|
||||||
|
}
|
||||||
} catch (const json::exception& e) {
|
} catch (const json::exception& e) {
|
||||||
i = T();
|
|
||||||
}
|
}
|
||||||
|
i = T();
|
||||||
}
|
}
|
||||||
|
|
||||||
GameBoxart() = default;
|
GameBoxart() = default;
|
||||||
|
@ -85,6 +91,7 @@ struct GameBoxart
|
||||||
loadProperty(fanartPath, j, "fanart_path");
|
loadProperty(fanartPath, j, "fanart_path");
|
||||||
loadProperty(boxartPath, j, "boxart_path");
|
loadProperty(boxartPath, j, "boxart_path");
|
||||||
loadProperty(scraped, j, "scraped");
|
loadProperty(scraped, j, "scraped");
|
||||||
|
loadProperty(found, j, "found");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue