Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed TheGamesDB scraper by adding a document tree segment 'scrapers' to the config file #802

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,10 @@ CMakeCache.txt
CMakeFiles
cmake_install.cmake
Makefile
CPackConfig.cmake
CPackSourceConfig.cmake

# Editors
.vscode/
*.sublime-project
*.sublime-workspace
2 changes: 2 additions & 0 deletions es-app/src/EmulationStation.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@

#define RESOURCE_VERSION_STRING "2,0,1\0"
#define RESOURCE_VERSION PROGRAM_VERSION_MAJOR,PROGRAM_VERSION_MINOR,PROGRAM_VERSION_MAINTENANCE

#define USER_AGENT_STRING "emulationstation/2.0.1"
36 changes: 32 additions & 4 deletions es-app/src/SystemData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
#include <iostream>
#include "Settings.h"
#include "FileSorts.h"
#include "scrapers/GamesDBScraper.h"

std::vector<SystemData*> SystemData::sSystemVector;

namespace fs = boost::filesystem;

SystemData::SystemData(const std::string& name, const std::string& fullName, const std::string& startPath, const std::vector<std::string>& extensions,
SystemData::SystemData(const std::string& name, const std::string& fullName, const std::string& startPath, const std::vector<std::string>& extensions,
const std::string& command, const std::vector<PlatformIds::PlatformId>& platformIds, const std::string& themeFolder)
{
mName = name;
Expand Down Expand Up @@ -67,7 +68,7 @@ std::string strreplace(std::string str, const std::string& replace, const std::s
size_t pos;
while((pos = str.find(replace)) != std::string::npos)
str = str.replace(pos, replace.length(), with.c_str(), with.length());

return str;
}

Expand Down Expand Up @@ -181,7 +182,7 @@ void SystemData::populateFolder(FileData* folder)
//this is a little complicated because we allow a list of extensions to be defined (delimited with a space)
//we first get the extension of the file itself:
extension = filePath.extension().string();

//fyi, folders *can* also match the extension and be added as games - this is mostly just to support higan
//see issue #75: https://github.com/Aloshi/EmulationStation/issues/75

Expand Down Expand Up @@ -282,7 +283,7 @@ bool SystemData::loadConfig()
{
const char* str = it->c_str();
PlatformIds::PlatformId platformId = PlatformIds::getPlatformId(str);

if(platformId == PlatformIds::PLATFORM_IGNORE)
{
// when platform is ignore, do not allow other platforms
Expand Down Expand Up @@ -322,6 +323,33 @@ bool SystemData::loadConfig()
}
}

// load the option API keeper
pugi::xml_node scrapers = doc.child("scrapers");
if (scrapers) {
LOG(LogInfo) << "loading scraper settings";
for (pugi::xml_node scraper = scrapers.child("scraper"); scraper; scraper=scrapers.next_sibling("scraper")) {
std::string name = scraper.child("name").text().get();
std::string URL = scraper.child("url").text().get();

std::string APIKey;
pugi::xml_node keyNode = scraper.child("APIKey");
if (keyNode) {
APIKey = keyNode.text().get();
if (name == "gamesdb") {
TheGamesDBRequest::APIkey = APIKey;
TheGamesDBRequest::URL = URL;
LOG(LogInfo) << "Set TheGamesDB API key: '" << APIKey << "'\n\tURL: "<< TheGamesDBRequest::URL << ".";
} else {
LOG(LogError) << "Unkown scraper: '" << name << "' tried to set API Key";
}
} else {
LOG(LogInfo) << "API '" << name << "' (path: '" << URL << "') has no API Key!";
}
}
} else {
LOG(LogInfo) << "es_systems.cfg does not have a scrapers list, scraping will be unavailable.";
}

return true;
}

Expand Down
24 changes: 12 additions & 12 deletions es-app/src/components/ScraperSearchComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "guis/GuiTextEditPopup.h"

ScraperSearchComponent::ScraperSearchComponent(Window* window, SearchType type) : GuiComponent(window),
mGrid(window, Eigen::Vector2i(4, 3)), mBusyAnim(window),
mGrid(window, Eigen::Vector2i(4, 3)), mBusyAnim(window),
mSearchType(type)
{
addChild(&mGrid);
Expand All @@ -39,7 +39,7 @@ ScraperSearchComponent::ScraperSearchComponent(Window* window, SearchType type)
mResultDesc = std::make_shared<TextComponent>(mWindow, "Result desc", Font::get(FONT_SIZE_SMALL), 0x777777FF);
mDescContainer->addChild(mResultDesc.get());
mDescContainer->setAutoScroll(true);

// metadata
auto font = Font::get(FONT_SIZE_SMALL); // this gets replaced in onSizeChanged() so its just a placeholder
const unsigned int mdColor = 0x777777FF;
Expand Down Expand Up @@ -80,7 +80,7 @@ ScraperSearchComponent::ScraperSearchComponent(Window* window, SearchType type)
void ScraperSearchComponent::onSizeChanged()
{
mGrid.setSize(mSize);

if(mSize.x() == 0 || mSize.y() == 0)
return;

Expand All @@ -89,10 +89,10 @@ void ScraperSearchComponent::onSizeChanged()
mGrid.setColWidthPerc(0, 0.02f); // looks better when this is higher in auto mode
else
mGrid.setColWidthPerc(0, 0.01f);

mGrid.setColWidthPerc(1, 0.25f);
mGrid.setColWidthPerc(2, 0.25f);

// row heights
if(mSearchType == ALWAYS_ACCEPT_FIRST_RESULT) // show name
mGrid.setRowHeightPerc(0, (mResultName->getFont()->getHeight() * 1.6f) / mGrid.getSize().y()); // result name
Expand All @@ -114,12 +114,12 @@ void ScraperSearchComponent::onSizeChanged()

// metadata
resizeMetadata();

if(mSearchType != ALWAYS_ACCEPT_FIRST_RESULT)
mDescContainer->setSize(mGrid.getColWidth(1)*boxartCellScale + mGrid.getColWidth(2), mResultDesc->getFont()->getHeight() * 3);
else
mDescContainer->setSize(mGrid.getColWidth(3)*boxartCellScale, mResultDesc->getFont()->getHeight() * 8);

mResultDesc->setSize(mDescContainer->getSize().x(), 0); // make desc text wrap at edge of container

mGrid.onSizeChanged();
Expand Down Expand Up @@ -294,7 +294,7 @@ void ScraperSearchComponent::updateInfoPane()
{
i = 0;
}

if(i != -1 && (int)mScraperResults.size() > i)
{
ScraperSearchResult& res = mScraperResults.at(i);
Expand Down Expand Up @@ -396,7 +396,7 @@ void ScraperSearchComponent::update(int deltaTime)
auto results = mSearchHandle->getResults();
auto statusString = mSearchHandle->getStatusString();

// we reset here because onSearchDone in auto mode can call mSkipCallback() which can call
// we reset here because onSearchDone in auto mode can call mSkipCallback() which can call
// another search() which will set our mSearchHandle to something important
mSearchHandle.reset();

Expand Down Expand Up @@ -450,9 +450,9 @@ void ScraperSearchComponent::openInputScreen(ScraperSearchParams& params)
};

stop();
mWindow->pushGui(new GuiTextEditPopup(mWindow, "SEARCH FOR",
mWindow->pushGui(new GuiTextEditPopup(mWindow, "SEARCH FOR",
// initial value is last search if there was one, otherwise the clean path name
params.nameOverride.empty() ? params.game->getCleanName() : params.nameOverride,
params.nameOverride.empty() ? params.game->getCleanName() : params.nameOverride,
searchForFunc, false, "SEARCH"));
}

Expand All @@ -461,7 +461,7 @@ std::vector<HelpPrompt> ScraperSearchComponent::getHelpPrompts()
std::vector<HelpPrompt> prompts = mGrid.getHelpPrompts();
if(getSelectedIndex() != -1)
prompts.push_back(HelpPrompt("a", "accept result"));

return prompts;
}

Expand Down
Loading