From 3915c55251d7112b718b545934f61aeb95988c36 Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Fri, 17 Jun 2022 16:13:58 +0200 Subject: [PATCH] boxart: skip invalid disks. fix disk id dash issue. save found status --- core/rend/boxart/gamesdb.cpp | 43 +++++++++++++++++++++++++++--------- core/rend/boxart/scraper.h | 11 +++++++-- 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/core/rend/boxart/gamesdb.cpp b/core/rend/boxart/gamesdb.cpp index 502479e2e..70430ef07 100644 --- a/core/rend/boxart/gamesdb.cpp +++ b/core/rend/boxart/gamesdb.cpp @@ -22,6 +22,7 @@ #include "imgread/common.h" #include "stdclass.h" #include "oslib/oslib.h" +#include #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,22 +283,33 @@ void TheGamesDb::scrape(GameBoxart& item) gameName = item.name; } - 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); - - if (uniqueId.empty() || !fetchGameInfo(item, url)) + if (!uniqueId.empty()) { - 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) 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; } diff --git a/core/rend/boxart/scraper.h b/core/rend/boxart/scraper.h index 48a1a1b36..64c77e2d6 100644 --- a/core/rend/boxart/scraper.h +++ b/core/rend/boxart/scraper.h @@ -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 { - i = j[propName].get(); + // asan error if missing contains(). json bug? + if (j.contains(propName)) { + i = j[propName].get(); + return; + } } catch (const json::exception& e) { - i = T(); } + 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"); } };