Added a ScreenScraper option to remove dots from game name searches when using the automatic scraper.

This commit is contained in:
Leon Styhre 2022-09-20 22:45:32 +02:00
parent 170234cd93
commit 02aba10a08
3 changed files with 30 additions and 4 deletions

View file

@ -896,6 +896,29 @@ void GuiScraperMenu::openOtherOptions()
} }
}); });
// Whether to remove dots from game names when searching using the automatic scraper.
auto scraperAutomaticRemoveDots = std::make_shared<SwitchComponent>();
scraperAutomaticRemoveDots->setState(
Settings::getInstance()->getBool("ScraperAutomaticRemoveDots"));
s->addWithLabel("REMOVE DOTS FROM SEARCHES WHEN AUTO-SCRAPING", scraperAutomaticRemoveDots);
s->addSaveFunc([scraperAutomaticRemoveDots, s] {
if (scraperAutomaticRemoveDots->getState() !=
Settings::getInstance()->getBool("ScraperAutomaticRemoveDots")) {
Settings::getInstance()->setBool("ScraperAutomaticRemoveDots",
scraperAutomaticRemoveDots->getState());
s->setNeedsSaving();
}
});
// This is not needed for TheGamesDB, so gray out the option if this scraper is selected.
if (Settings::getInstance()->getString("Scraper") == "thegamesdb") {
scraperAutomaticRemoveDots->setEnabled(false);
scraperAutomaticRemoveDots->setOpacity(DISABLED_OPACITY);
scraperAutomaticRemoveDots->getParent()
->getChild(scraperAutomaticRemoveDots->getChildIndex() - 1)
->setOpacity(DISABLED_OPACITY);
}
// Whether to fallback to additional regions. // Whether to fallback to additional regions.
auto scraperRegionFallback = std::make_shared<SwitchComponent>(mWindow); auto scraperRegionFallback = std::make_shared<SwitchComponent>(mWindow);
scraperRegionFallback->setState(Settings::getInstance()->getBool("ScraperRegionFallback")); scraperRegionFallback->setState(Settings::getInstance()->getBool("ScraperRegionFallback"));

View file

@ -726,8 +726,8 @@ std::string ScreenScraperRequest::ScreenScraperConfig::getGameSearchUrl(
const std::string gameName) const const std::string gameName) const
{ {
std::string screenScraperURL; std::string screenScraperURL;
std::string searchName = gameName; std::string searchName {gameName};
bool singleSearch = false; bool singleSearch {false};
// Trim leading and trailing whitespaces. // Trim leading and trailing whitespaces.
searchName = Utils::String::trim(searchName); searchName = Utils::String::trim(searchName);
@ -771,8 +771,8 @@ std::string ScreenScraperRequest::ScreenScraperConfig::getGameSearchUrl(
// Another issue is that ScreenScraper removes the word "the" from the search string, which // Another issue is that ScreenScraper removes the word "the" from the search string, which
// could also lead to an error for short game names. // could also lead to an error for short game names.
if (!singleSearch) { if (!singleSearch) {
std::string removeThe = std::string removeThe {
Utils::String::replace(Utils::String::toUpper(searchName), "THE ", ""); Utils::String::replace(Utils::String::toUpper(searchName), "THE ", "")};
// Any additional spaces must also be removed. // Any additional spaces must also be removed.
removeThe.erase(removeThe.begin(), removeThe.erase(removeThe.begin(),
std::find_if(removeThe.begin(), removeThe.end(), [](char c) { std::find_if(removeThe.begin(), removeThe.end(), [](char c) {
@ -788,6 +788,8 @@ std::string ScreenScraperRequest::ScreenScraperConfig::getGameSearchUrl(
} }
if (automaticMode || singleSearch) { if (automaticMode || singleSearch) {
if (Settings::getInstance()->getBool("ScraperAutomaticRemoveDots"))
searchName = Utils::String::replace(searchName, ".", "");
screenScraperURL = API_URL_BASE + "/jeuInfos.php?devid=" + screenScraperURL = API_URL_BASE + "/jeuInfos.php?devid=" +
Utils::String::scramble(API_DEV_U, API_DEV_KEY) + Utils::String::scramble(API_DEV_U, API_DEV_KEY) +
"&devpassword=" + Utils::String::scramble(API_DEV_P, API_DEV_KEY) + "&devpassword=" + Utils::String::scramble(API_DEV_P, API_DEV_KEY) +

View file

@ -125,6 +125,7 @@ void Settings::setDefaults()
mBoolMap["ScraperRespectExclusions"] = {true, true}; mBoolMap["ScraperRespectExclusions"] = {true, true};
mBoolMap["ScraperExcludeRecursively"] = {true, true}; mBoolMap["ScraperExcludeRecursively"] = {true, true};
mBoolMap["ScraperConvertUnderscores"] = {true, true}; mBoolMap["ScraperConvertUnderscores"] = {true, true};
mBoolMap["ScraperAutomaticRemoveDots"] = {true, true};
mBoolMap["ScraperRegionFallback"] = {true, true}; mBoolMap["ScraperRegionFallback"] = {true, true};
mBoolMap["ScraperRetryPeerVerification"] = {false, false}; mBoolMap["ScraperRetryPeerVerification"] = {false, false};