diff --git a/es-app/src/scrapers/ScreenScraper.cpp b/es-app/src/scrapers/ScreenScraper.cpp index 50cddbafe..49403a01f 100644 --- a/es-app/src/scrapers/ScreenScraper.cpp +++ b/es-app/src/scrapers/ScreenScraper.cpp @@ -614,7 +614,6 @@ void ScreenScraperRequest::processGame(const pugi::xml_document& xmldoc, // Media super-node. pugi::xml_node media_list {game.child("medias")}; - bool regionFallback {false}; if (media_list) { // 3D box. @@ -630,19 +629,28 @@ void ScreenScraperRequest::processGame(const pugi::xml_document& xmldoc, processMedia(result, media_list, ssConfig.media_fanart, result.fanartUrl, result.fanartFormat, region); // Marquee (wheel). - regionFallback = processMedia(result, media_list, ssConfig.media_marquee, - result.marqueeUrl, result.marqueeFormat, region); - // Marquee HD (wheel-hd) fallback if no regular wheel image was found or if the - // image found was a fallback to another region than the one requested. If it was - // a fallback to another region then it will only get replaced with the wheel-hd - // image if that is matching the requested region. - if (regionFallback || result.marqueeUrl == "") { - std::string marqueeUrlTemp {result.marqueeUrl}; - if (processMedia(result, media_list, ssConfig.media_marquee_hd, result.marqueeUrl, - result.marqueeFormat, region) && - marqueeUrlTemp != "") { - result.marqueeUrl = marqueeUrlTemp; - } + // There are two media types for the marquee named "wheel" and "wheel"-hd that should + // be considered equivalent, i.e. the most closely matching region should be considered + // across both media types. This is a logical error, but as it's caused by an issue on + // the server side this workaround is still required. + int regionPosWheel {0}; + std::string fileURLWheel; + std::string fileFormatWheel; + regionPosWheel = processMedia(result, media_list, ssConfig.media_marquee, fileURLWheel, + fileFormatWheel, region); + int regionPosWheelHD {0}; + std::string fileURLWheelHD; + std::string fileFormatWheelHD; + regionPosWheelHD = processMedia(result, media_list, ssConfig.media_marquee_hd, + fileURLWheelHD, fileFormatWheelHD, region); + if ((regionPosWheelHD != 0 && regionPosWheelHD <= regionPosWheel) || + regionPosWheel == 0) { + result.marqueeUrl = fileURLWheelHD; + result.marqueeFormat = fileFormatWheelHD; + } + else { + result.marqueeUrl = fileURLWheel; + result.marqueeFormat = fileFormatWheel; } // Physical media. processMedia(result, media_list, ssConfig.media_physicalmedia, result.physicalmediaUrl, @@ -673,15 +681,15 @@ void ScreenScraperRequest::processGame(const pugi::xml_document& xmldoc, } } -bool ScreenScraperRequest::processMedia(ScraperSearchResult& result, - const pugi::xml_node& media_list, - std::string& mediaType, - std::string& fileURL, - std::string& fileFormat, - const std::string& region) +int ScreenScraperRequest::processMedia(ScraperSearchResult& result, + const pugi::xml_node& media_list, + std::string& mediaType, + std::string& fileURL, + std::string& fileFormat, + const std::string& region) { pugi::xml_node art {pugi::xml_node(nullptr)}; - bool regionFallback {false}; + int regionPos {0}; // Do an XPath query for media[type='$media_type'], then filter by region. // We need to do this because any child of 'medias' has the form @@ -712,11 +720,11 @@ bool ScreenScraperRequest::processMedia(ScraperSearchResult& result, if (art) break; + ++regionPos; + for (auto node : results) { if (node.node().attribute("region").value() == regionEntry) { art = node.node(); - if (region != regionEntry) - regionFallback = true; break; } } @@ -740,7 +748,7 @@ bool ScreenScraperRequest::processMedia(ScraperSearchResult& result, << mediaType << "\""; } - return regionFallback; + return regionPos; } std::string ScreenScraperRequest::ScreenScraperConfig::getGameSearchUrl(const std::string& gameName, diff --git a/es-app/src/scrapers/ScreenScraper.h b/es-app/src/scrapers/ScreenScraper.h index 31f4dd39f..77bdfa3e8 100644 --- a/es-app/src/scrapers/ScreenScraper.h +++ b/es-app/src/scrapers/ScreenScraper.h @@ -123,12 +123,12 @@ protected: std::vector& results) override; void processGame(const pugi::xml_document& xmldoc, std::vector& results); - bool processMedia(ScraperSearchResult& result, - const pugi::xml_node& media_list, - std::string& mediaType, - std::string& fileURL, - std::string& fileFormat, - const std::string& region); + int processMedia(ScraperSearchResult& result, + const pugi::xml_node& media_list, + std::string& mediaType, + std::string& fileURL, + std::string& fileFormat, + const std::string& region); bool isGameRequest() { return !mRequestQueue; } std::queue>* mRequestQueue;