Fixed ScreenScraper handling of missing game metadata.

This commit is contained in:
Leon Styhre 2020-08-02 14:19:51 +02:00
parent 101bdf4bfc
commit dec3a74e16
2 changed files with 50 additions and 32 deletions

View file

@ -304,21 +304,25 @@ void processGame(const Value& game, std::vector<ScraperSearchResult>& results)
LOG(LogDebug) << "GamesDBJSONScraper::processGame(): Release Date (parsed): " << LOG(LogDebug) << "GamesDBJSONScraper::processGame(): Release Date (parsed): " <<
result.mdl.get("releasedate"); result.mdl.get("releasedate");
} }
if (game.HasMember("developers") && game["developers"].IsArray()) { if (game.HasMember("developers") && game["developers"].IsArray()) {
result.mdl.set("developer", getDeveloperString(game["developers"])); result.mdl.set("developer", getDeveloperString(game["developers"]));
LOG(LogDebug) << "GamesDBJSONScraper::processGame(): Developer: " << LOG(LogDebug) << "GamesDBJSONScraper::processGame(): Developer: " <<
result.mdl.get("developer"); result.mdl.get("developer");
} }
if (game.HasMember("publishers") && game["publishers"].IsArray()) { if (game.HasMember("publishers") && game["publishers"].IsArray()) {
result.mdl.set("publisher", getPublisherString(game["publishers"])); result.mdl.set("publisher", getPublisherString(game["publishers"]));
LOG(LogDebug) << "GamesDBJSONScraper::processGame(): Publisher: " << LOG(LogDebug) << "GamesDBJSONScraper::processGame(): Publisher: " <<
result.mdl.get("publisher"); result.mdl.get("publisher");
} }
if (game.HasMember("genres") && game["genres"].IsArray()) { if (game.HasMember("genres") && game["genres"].IsArray()) {
result.mdl.set("genre", getGenreString(game["genres"])); result.mdl.set("genre", getGenreString(game["genres"]));
LOG(LogDebug) << "GamesDBJSONScraper::processGame(): Genre: " << LOG(LogDebug) << "GamesDBJSONScraper::processGame(): Genre: " <<
result.mdl.get("genre"); result.mdl.get("genre");
} }
if (game.HasMember("players") && game["players"].IsInt()) { if (game.HasMember("players") && game["players"].IsInt()) {
result.mdl.set("players", std::to_string(game["players"].GetInt())); result.mdl.set("players", std::to_string(game["players"].GetInt()));
LOG(LogDebug) << "GamesDBJSONScraper::processGame(): Players: " << LOG(LogDebug) << "GamesDBJSONScraper::processGame(): Players: " <<

View file

@ -232,6 +232,22 @@ void ScreenScraperRequest::processGame(const pugi::xml_document& xmldoc,
// Name fallback: US, WOR(LD). ( Xpath: Data/jeu[0]/noms/nom[*] ). // Name fallback: US, WOR(LD). ( Xpath: Data/jeu[0]/noms/nom[*] ).
result.mdl.set("name", find_child_by_attribute_list(game.child("noms"), result.mdl.set("name", find_child_by_attribute_list(game.child("noms"),
"nom", "region", { region, "wor", "us" , "ss", "eu", "jp" }).text().get()); "nom", "region", { region, "wor", "us" , "ss", "eu", "jp" }).text().get());
LOG(LogDebug) << "ScreenScraperRequest::processGame(): Name: " <<
result.mdl.get("name");
// Validate rating.
if (Settings::getInstance()->getBool("ScrapeRatings") && game.child("note")) {
float ratingVal = (game.child("note").text().as_int() / 20.0f);
// Round up to the closest .1 value, i.e. to the closest half-star.
ratingVal = Math::ceilf(ratingVal / 0.1) / 10;
std::stringstream ss;
ss << ratingVal;
if (ratingVal > 0) {
result.mdl.set("rating", ss.str());
LOG(LogDebug) << "ScreenScraperRequest::processGame(): Rating: " <<
result.mdl.get("rating");
}
}
// Description fallback language: EN, WOR(LD). // Description fallback language: EN, WOR(LD).
std::string description = find_child_by_attribute_list(game.child("synopsis"), std::string description = find_child_by_attribute_list(game.child("synopsis"),
@ -240,10 +256,6 @@ void ScreenScraperRequest::processGame(const pugi::xml_document& xmldoc,
if (!description.empty()) if (!description.empty())
result.mdl.set("desc", Utils::String::replace(description, "&nbsp;", " ")); result.mdl.set("desc", Utils::String::replace(description, "&nbsp;", " "));
// Genre fallback language: EN. ( Xpath: Data/jeu[0]/genres/genre[*] ).
result.mdl.set("genre", find_child_by_attribute_list(game.child("genres"),
"genre", "langue", { language, "en" }).text().get());
// Get the date proper. The API returns multiple 'date' children nodes to the 'dates' // Get the date proper. The API returns multiple 'date' children nodes to the 'dates'
// main child of 'jeu'. // main child of 'jeu'.
// Date fallback: WOR(LD), US, SS, JP, EU. // Date fallback: WOR(LD), US, SS, JP, EU.
@ -260,43 +272,45 @@ void ScreenScraperRequest::processGame(const pugi::xml_document& xmldoc,
Utils::Time::stringToTime(_date, "%Y"))); Utils::Time::stringToTime(_date, "%Y")));
} }
/// Developer for the game( Xpath: Data/jeu[0]/developpeur ). if (_date.length() > 0) {
std::string developer = game.child("developpeur").text().get();
if (!developer.empty())
result.mdl.set("developer", Utils::String::replace(developer, "&nbsp;", " "));
// Publisher for the game ( Xpath: Data/jeu[0]/editeur ).
std::string publisher = game.child("editeur").text().get();
if (!publisher.empty())
result.mdl.set("publisher", Utils::String::replace(publisher, "&nbsp;", " "));
// Players.
result.mdl.set("players", game.child("joueurs").text().get());
// Validate rating.
if (Settings::getInstance()->getBool("ScrapeRatings") && game.child("note")) {
float ratingVal = (game.child("note").text().as_int() / 20.0f);
// Round up to the closest .1 value, i.e. to the closest half-star.
ratingVal = Math::ceilf(ratingVal / 0.1) / 10;
std::stringstream ss;
ss << ratingVal;
result.mdl.set("rating", ss.str());
}
LOG(LogDebug) << "ScreenScraperRequest::processGame(): Name: " <<
result.mdl.get("name");
LOG(LogDebug) << "ScreenScraperRequest::processGame(): Release Date (unparsed): " << LOG(LogDebug) << "ScreenScraperRequest::processGame(): Release Date (unparsed): " <<
_date; _date;
LOG(LogDebug) << "ScreenScraperRequest::processGame(): Release Date (parsed): " << LOG(LogDebug) << "ScreenScraperRequest::processGame(): Release Date (parsed): " <<
result.mdl.get("releasedate"); result.mdl.get("releasedate");
}
/// Developer for the game( Xpath: Data/jeu[0]/developpeur ).
std::string developer = game.child("developpeur").text().get();
if (!developer.empty()) {
result.mdl.set("developer", Utils::String::replace(developer, "&nbsp;", " "));
LOG(LogDebug) << "ScreenScraperRequest::processGame(): Developer: " << LOG(LogDebug) << "ScreenScraperRequest::processGame(): Developer: " <<
result.mdl.get("developer"); result.mdl.get("developer");
}
// Publisher for the game ( Xpath: Data/jeu[0]/editeur ).
std::string publisher = game.child("editeur").text().get();
if (!publisher.empty()) {
result.mdl.set("publisher", Utils::String::replace(publisher, "&nbsp;", " "));
LOG(LogDebug) << "ScreenScraperRequest::processGame(): Publisher: " << LOG(LogDebug) << "ScreenScraperRequest::processGame(): Publisher: " <<
result.mdl.get("publisher"); result.mdl.get("publisher");
}
// Genre fallback language: EN. ( Xpath: Data/jeu[0]/genres/genre[*] ).
std::string genre = find_child_by_attribute_list(game.child("genres"),
"genre", "langue", { language, "en" }).text().get();
if (!genre.empty()) {
result.mdl.set("genre", genre);
LOG(LogDebug) << "ScreenScraperRequest::processGame(): Genre: " << LOG(LogDebug) << "ScreenScraperRequest::processGame(): Genre: " <<
result.mdl.get("genre"); result.mdl.get("genre");
}
// Players.
std::string players = game.child("joueurs").text().get();
if (!players.empty()) {
result.mdl.set("players", players);
LOG(LogDebug) << "ScreenScraperRequest::processGame(): Players: " << LOG(LogDebug) << "ScreenScraperRequest::processGame(): Players: " <<
result.mdl.get("players"); result.mdl.get("players");
}
// Media super-node. // Media super-node.
pugi::xml_node media_list = game.child("medias"); pugi::xml_node media_list = game.child("medias");