From 02aba10a085d025653472d3853104e400c5669eb Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Tue, 20 Sep 2022 22:45:32 +0200 Subject: [PATCH] Added a ScreenScraper option to remove dots from game name searches when using the automatic scraper. --- es-app/src/guis/GuiScraperMenu.cpp | 23 +++++++++++++++++++++++ es-app/src/scrapers/ScreenScraper.cpp | 10 ++++++---- es-core/src/Settings.cpp | 1 + 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/es-app/src/guis/GuiScraperMenu.cpp b/es-app/src/guis/GuiScraperMenu.cpp index 2a76e9edf..90da182d7 100644 --- a/es-app/src/guis/GuiScraperMenu.cpp +++ b/es-app/src/guis/GuiScraperMenu.cpp @@ -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(); + 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. auto scraperRegionFallback = std::make_shared(mWindow); scraperRegionFallback->setState(Settings::getInstance()->getBool("ScraperRegionFallback")); diff --git a/es-app/src/scrapers/ScreenScraper.cpp b/es-app/src/scrapers/ScreenScraper.cpp index c9783fc3d..2d9db925e 100644 --- a/es-app/src/scrapers/ScreenScraper.cpp +++ b/es-app/src/scrapers/ScreenScraper.cpp @@ -726,8 +726,8 @@ std::string ScreenScraperRequest::ScreenScraperConfig::getGameSearchUrl( const std::string gameName) const { std::string screenScraperURL; - std::string searchName = gameName; - bool singleSearch = false; + std::string searchName {gameName}; + bool singleSearch {false}; // Trim leading and trailing whitespaces. 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 // could also lead to an error for short game names. if (!singleSearch) { - std::string removeThe = - Utils::String::replace(Utils::String::toUpper(searchName), "THE ", ""); + std::string removeThe { + Utils::String::replace(Utils::String::toUpper(searchName), "THE ", "")}; // Any additional spaces must also be removed. removeThe.erase(removeThe.begin(), std::find_if(removeThe.begin(), removeThe.end(), [](char c) { @@ -788,6 +788,8 @@ std::string ScreenScraperRequest::ScreenScraperConfig::getGameSearchUrl( } if (automaticMode || singleSearch) { + if (Settings::getInstance()->getBool("ScraperAutomaticRemoveDots")) + searchName = Utils::String::replace(searchName, ".", ""); screenScraperURL = API_URL_BASE + "/jeuInfos.php?devid=" + Utils::String::scramble(API_DEV_U, API_DEV_KEY) + "&devpassword=" + Utils::String::scramble(API_DEV_P, API_DEV_KEY) + diff --git a/es-core/src/Settings.cpp b/es-core/src/Settings.cpp index fea763b68..e3c7c7705 100644 --- a/es-core/src/Settings.cpp +++ b/es-core/src/Settings.cpp @@ -125,6 +125,7 @@ void Settings::setDefaults() mBoolMap["ScraperRespectExclusions"] = {true, true}; mBoolMap["ScraperExcludeRecursively"] = {true, true}; mBoolMap["ScraperConvertUnderscores"] = {true, true}; + mBoolMap["ScraperAutomaticRemoveDots"] = {true, true}; mBoolMap["ScraperRegionFallback"] = {true, true}; mBoolMap["ScraperRetryPeerVerification"] = {false, false};