Added a scraper setting to convert underscores _ to spaces when searching.

This commit is contained in:
Leon Styhre 2022-04-09 15:14:48 +02:00
parent 63e6176d5a
commit 21f21c20f5
5 changed files with 24 additions and 0 deletions

View file

@ -879,6 +879,20 @@ void GuiScraperMenu::openOtherOptions()
->setOpacity(DISABLED_OPACITY);
}
// Convert underscores to spaces when searching.
auto scraperConvertUnderscores = std::make_shared<SwitchComponent>();
scraperConvertUnderscores->setState(
Settings::getInstance()->getBool("ScraperConvertUnderscores"));
s->addWithLabel("CONVERT UNDERSCORES TO SPACES WHEN SEARCHING", scraperConvertUnderscores);
s->addSaveFunc([scraperConvertUnderscores, s] {
if (scraperConvertUnderscores->getState() !=
Settings::getInstance()->getBool("ScraperConvertUnderscores")) {
Settings::getInstance()->setBool("ScraperConvertUnderscores",
scraperConvertUnderscores->getState());
s->setNeedsSaving();
}
});
// Retry search on peer verification errors (TLS/certificate issues).
auto retry_peer_verification = std::make_shared<SwitchComponent>();
retry_peer_verification->setState(

View file

@ -901,6 +901,9 @@ void GuiScraperSearch::openInputScreen(ScraperSearchParams& params)
searchString = params.nameOverride;
}
if (Settings::getInstance()->getBool("ScraperConvertUnderscores"))
searchString = Utils::String::replace(searchString, "_", " ");
if (Settings::getInstance()->getBool("VirtualKeyboard")) {
mWindow->pushGui(new GuiTextEditKeyboardPopup(getHelpStyle(), "REFINE SEARCH", searchString,
searchForFunc, false, "SEARCH",

View file

@ -178,6 +178,9 @@ void thegamesdb_generate_json_scraper_requests(
// Trim leading and trailing whitespaces.
cleanName = Utils::String::trim(cleanName);
if (Settings::getInstance()->getBool("ScraperConvertUnderscores"))
cleanName = Utils::String::replace(cleanName, "_", " ");
path += "/Games/ByGameName?" + apiKey +
"&fields=players,publishers,genres,overview,last_updated,rating,"
"platform,coop,youtube,os,processor,ram,hdd,video,sound,alternates&name=" +

View file

@ -692,6 +692,9 @@ std::string ScreenScraperRequest::ScreenScraperConfig::getGameSearchUrl(
// Trim leading and trailing whitespaces.
searchName = Utils::String::trim(searchName);
if (Settings::getInstance()->getBool("ScraperConvertUnderscores"))
searchName = Utils::String::replace(searchName, "_", " ");
// If only whitespaces were entered as the search string, then search using a random string
// that will not return any results. This is a quick and dirty way to avoid french error
// messages about malformed URLs that would surely confuse the user.

View file

@ -126,6 +126,7 @@ void Settings::setDefaults()
mBoolMap["ScraperSemiautomatic"] = {true, true};
mBoolMap["ScraperRespectExclusions"] = {true, true};
mBoolMap["ScraperExcludeRecursively"] = {true, true};
mBoolMap["ScraperConvertUnderscores"] = {true, true};
mBoolMap["ScraperRetryPeerVerification"] = {false, false};
// UI settings.