From 92f5284bf33e896775ccb0b30c9679f8cb870b39 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sat, 15 Jan 2022 13:16:23 +0100 Subject: [PATCH] Added support for scraping fan art images. Also added scraping of box back covers when using TheGamesDB. --- es-app/src/FileData.cpp | 6 ++++++ es-app/src/FileData.h | 1 + es-app/src/MediaViewer.cpp | 3 +++ es-app/src/guis/GuiScraperMenu.cpp | 19 ++++++++++--------- es-app/src/guis/GuiScraperSearch.cpp | 1 + es-app/src/scrapers/GamesDBJSONScraper.cpp | 8 ++++++++ es-app/src/scrapers/Scraper.cpp | 8 ++++++++ es-app/src/scrapers/Scraper.h | 2 ++ es-app/src/scrapers/ScreenScraper.cpp | 3 +++ es-app/src/scrapers/ScreenScraper.h | 1 + .../src/views/gamelist/BasicGameListView.cpp | 7 +++++++ .../src/views/gamelist/GridGameListView.cpp | 7 +++++++ es-core/src/Settings.cpp | 1 + 13 files changed, 58 insertions(+), 9 deletions(-) diff --git a/es-app/src/FileData.cpp b/es-app/src/FileData.cpp index e257e47be..a796c5b03 100644 --- a/es-app/src/FileData.cpp +++ b/es-app/src/FileData.cpp @@ -278,6 +278,12 @@ const std::string FileData::getCoverPath() const return getMediafilePath("covers"); } +const std::string FileData::getFanArtPath() const +{ + // Return path to the fan art image. + return getMediafilePath("fanart"); +} + const std::string FileData::getMarqueePath() const { // Return path to the marquee image. diff --git a/es-app/src/FileData.h b/es-app/src/FileData.h index c66d4db7b..4a195046e 100644 --- a/es-app/src/FileData.h +++ b/es-app/src/FileData.h @@ -65,6 +65,7 @@ public: const std::string get3DBoxPath() const; const std::string getBackCoverPath() const; const std::string getCoverPath() const; + const std::string getFanArtPath() const; const std::string getMarqueePath() const; const std::string getPhysicalMediaPath() const; const std::string getMiximagePath() const; diff --git a/es-app/src/MediaViewer.cpp b/es-app/src/MediaViewer.cpp index 3013a0546..c2000e846 100644 --- a/es-app/src/MediaViewer.cpp +++ b/es-app/src/MediaViewer.cpp @@ -183,6 +183,9 @@ void MediaViewer::findMedia() mScreenshotIndex = static_cast(mImageFiles.size() - 1); } + if ((mediaFile = mGame->getFanArtPath()) != "") + mImageFiles.push_back(mediaFile); + if ((mediaFile = mGame->getMiximagePath()) != "") mImageFiles.push_back(mediaFile); diff --git a/es-app/src/guis/GuiScraperMenu.cpp b/es-app/src/guis/GuiScraperMenu.cpp index cb817fc2a..70e47c271 100644 --- a/es-app/src/guis/GuiScraperMenu.cpp +++ b/es-app/src/guis/GuiScraperMenu.cpp @@ -353,15 +353,16 @@ void GuiScraperMenu::openContentOptions() } }); - // Box back cover images are not supported by TheGamesDB, so gray out the option if this - // scraper is selected. - if (Settings::getInstance()->getString("Scraper") == "thegamesdb") { - scrapeBackCovers->setEnabled(false); - scrapeBackCovers->setOpacity(DISABLED_OPACITY); - scrapeBackCovers->getParent() - ->getChild(scrapeBackCovers->getChildIndex() - 1) - ->setOpacity(DISABLED_OPACITY); - } + // Scrape fan art images. + auto scrapeFanArt = std::make_shared(mWindow); + scrapeFanArt->setState(Settings::getInstance()->getBool("ScrapeFanArt")); + s->addWithLabel("FAN ART IMAGES", scrapeFanArt); + s->addSaveFunc([scrapeFanArt, s] { + if (scrapeFanArt->getState() != Settings::getInstance()->getBool("ScrapeFanArt")) { + Settings::getInstance()->setBool("ScrapeFanArt", scrapeFanArt->getState()); + s->setNeedsSaving(); + } + }); // Scrape marquee images. auto scrape_marquees = std::make_shared(mWindow); diff --git a/es-app/src/guis/GuiScraperSearch.cpp b/es-app/src/guis/GuiScraperSearch.cpp index 9fb163166..4bcf5f5cb 100644 --- a/es-app/src/guis/GuiScraperSearch.cpp +++ b/es-app/src/guis/GuiScraperSearch.cpp @@ -733,6 +733,7 @@ void GuiScraperSearch::update(int deltaTime) results_scrape[i].box3DUrl = it->box3DUrl; results_scrape[i].backcoverUrl = it->backcoverUrl; results_scrape[i].coverUrl = it->coverUrl; + results_scrape[i].fanartUrl = it->fanartUrl; results_scrape[i].marqueeUrl = it->marqueeUrl; results_scrape[i].screenshotUrl = it->screenshotUrl; results_scrape[i].titlescreenUrl = it->titlescreenUrl; diff --git a/es-app/src/scrapers/GamesDBJSONScraper.cpp b/es-app/src/scrapers/GamesDBJSONScraper.cpp index b9c2d0e23..64a3464d1 100644 --- a/es-app/src/scrapers/GamesDBJSONScraper.cpp +++ b/es-app/src/scrapers/GamesDBJSONScraper.cpp @@ -402,6 +402,7 @@ void processMediaURLs(const Value& images, result.gameID = it->name.GetString(); const Value& gameMedia = images[it->name]; result.coverUrl = ""; + result.fanartUrl = ""; result.marqueeUrl = ""; result.screenshotUrl = ""; result.titlescreenUrl = ""; @@ -420,6 +421,13 @@ void processMediaURLs(const Value& images, if (mediatype == "boxart" && mediaside == "front") if (gameMedia[i]["filename"].IsString()) result.coverUrl = base_url + gameMedia[i]["filename"].GetString(); + if (mediatype == "boxart" && mediaside == "back") + if (gameMedia[i]["filename"].IsString()) + result.backcoverUrl = base_url + gameMedia[i]["filename"].GetString(); + // Only process the first fanart result. + if (mediatype == "fanart" && result.fanartUrl == "") + if (gameMedia[i]["filename"].IsString()) + result.fanartUrl = base_url + gameMedia[i]["filename"].GetString(); if (mediatype == "clearlogo") if (gameMedia[i]["filename"].IsString()) result.marqueeUrl = base_url + gameMedia[i]["filename"].GetString(); diff --git a/es-app/src/scrapers/Scraper.cpp b/es-app/src/scrapers/Scraper.cpp index 98948883e..e2ea46a4b 100644 --- a/es-app/src/scrapers/Scraper.cpp +++ b/es-app/src/scrapers/Scraper.cpp @@ -212,6 +212,14 @@ MDResolveHandle::MDResolveHandle(const ScraperSearchResult& result, mediaFileInfo.resizeFile = true; scrapeFiles.push_back(mediaFileInfo); } + if (Settings::getInstance()->getBool("ScrapeFanArt") && result.fanartUrl != "") { + mediaFileInfo.fileURL = result.fanartUrl; + mediaFileInfo.fileFormat = result.fanartFormat; + mediaFileInfo.subDirectory = "fanart"; + mediaFileInfo.existingMediaFile = search.game->getFanArtPath(); + mediaFileInfo.resizeFile = true; + scrapeFiles.push_back(mediaFileInfo); + } if (Settings::getInstance()->getBool("ScrapePhysicalMedia") && result.physicalmediaUrl != "") { mediaFileInfo.fileURL = result.physicalmediaUrl; mediaFileInfo.fileFormat = result.physicalmediaFormat; diff --git a/es-app/src/scrapers/Scraper.h b/es-app/src/scrapers/Scraper.h index fbe1cb8b5..ac669745b 100644 --- a/es-app/src/scrapers/Scraper.h +++ b/es-app/src/scrapers/Scraper.h @@ -69,6 +69,7 @@ struct ScraperSearchResult { std::string box3DUrl; std::string backcoverUrl; std::string coverUrl; + std::string fanartUrl; std::string marqueeUrl; std::string physicalmediaUrl; std::string screenshotUrl; @@ -79,6 +80,7 @@ struct ScraperSearchResult { std::string box3DFormat; std::string backcoverFormat; std::string coverFormat; + std::string fanartFormat; std::string marqueeFormat; std::string physicalmediaFormat; std::string screenshotFormat; diff --git a/es-app/src/scrapers/ScreenScraper.cpp b/es-app/src/scrapers/ScreenScraper.cpp index 4224ba3e0..569fa62b5 100644 --- a/es-app/src/scrapers/ScreenScraper.cpp +++ b/es-app/src/scrapers/ScreenScraper.cpp @@ -559,6 +559,9 @@ void ScreenScraperRequest::processGame(const pugi::xml_document& xmldoc, // Box cover. processMedia(result, media_list, ssConfig.media_cover, result.coverUrl, result.coverFormat, region); + // Fan art. + processMedia(result, media_list, ssConfig.media_fanart, result.fanartUrl, + result.fanartFormat, region); // Marquee (wheel). processMedia(result, media_list, ssConfig.media_marquee, result.marqueeUrl, result.marqueeFormat, region); diff --git a/es-app/src/scrapers/ScreenScraper.h b/es-app/src/scrapers/ScreenScraper.h index 68e509733..7c2c9da2d 100644 --- a/es-app/src/scrapers/ScreenScraper.h +++ b/es-app/src/scrapers/ScreenScraper.h @@ -73,6 +73,7 @@ public: std::string media_3dbox = "box-3D"; std::string media_backcover = "box-2D-back"; std::string media_cover = "box-2D"; + std::string media_fanart = "fanart"; std::string media_marquee = "wheel"; std::string media_physicalmedia = "support-2D"; std::string media_screenshot = "ss"; diff --git a/es-app/src/views/gamelist/BasicGameListView.cpp b/es-app/src/views/gamelist/BasicGameListView.cpp index 381d4d60a..80dc2ce5f 100644 --- a/es-app/src/views/gamelist/BasicGameListView.cpp +++ b/es-app/src/views/gamelist/BasicGameListView.cpp @@ -272,6 +272,13 @@ void BasicGameListView::removeMedia(FileData* game) removeEmptyDirFunc(systemMediaDir, mediaType, path); } + while (Utils::FileSystem::exists(game->getFanArtPath())) { + mediaType = "fanart"; + path = game->getFanArtPath(); + Utils::FileSystem::removeFile(path); + removeEmptyDirFunc(systemMediaDir, mediaType, path); + } + while (Utils::FileSystem::exists(game->getMarqueePath())) { mediaType = "marquees"; path = game->getMarqueePath(); diff --git a/es-app/src/views/gamelist/GridGameListView.cpp b/es-app/src/views/gamelist/GridGameListView.cpp index 189d423e1..840942c4d 100644 --- a/es-app/src/views/gamelist/GridGameListView.cpp +++ b/es-app/src/views/gamelist/GridGameListView.cpp @@ -625,6 +625,13 @@ void GridGameListView::removeMedia(FileData* game) removeEmptyDirFunc(systemMediaDir, mediaType, path); } + while (Utils::FileSystem::exists(game->getFanArtPath())) { + mediaType = "fanart"; + path = game->getFanArtPath(); + Utils::FileSystem::removeFile(path); + removeEmptyDirFunc(systemMediaDir, mediaType, path); + } + while (Utils::FileSystem::exists(game->getMarqueePath())) { mediaType = "marquees"; path = game->getMarqueePath(); diff --git a/es-core/src/Settings.cpp b/es-core/src/Settings.cpp index 6642e961f..3eb6276fa 100644 --- a/es-core/src/Settings.cpp +++ b/es-core/src/Settings.cpp @@ -97,6 +97,7 @@ void Settings::setDefaults() mBoolMap["ScrapeTitleScreens"] = {true, true}; mBoolMap["ScrapeCovers"] = {true, true}; mBoolMap["ScrapeBackCovers"] = {true, true}; + mBoolMap["ScrapeFanArt"] = {true, true}; mBoolMap["ScrapeMarquees"] = {true, true}; mBoolMap["Scrape3DBoxes"] = {true, true}; mBoolMap["ScrapePhysicalMedia"] = {true, true};