mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-01-29 19:55:37 +00:00
Partial implementation for TheGamesDB scraper.
Still needs a way to display error messages.
This commit is contained in:
parent
3105073e50
commit
9ce511cc71
|
@ -1,40 +1,70 @@
|
||||||
#include "GamesDBScraper.h"
|
#include "GamesDBScraper.h"
|
||||||
#include "../components/AsyncReqComponent.h"
|
#include "../components/AsyncReqComponent.h"
|
||||||
#include "../Log.h"
|
#include "../Log.h"
|
||||||
|
#include "../pugiXML/pugixml.hpp"
|
||||||
|
|
||||||
std::vector<MetaDataList> GamesDBScraper::getResults(ScraperSearchParams params)
|
std::vector<MetaDataList> GamesDBScraper::getResults(ScraperSearchParams params)
|
||||||
{
|
{
|
||||||
std::shared_ptr<HttpReq> req = makeHttpReq();
|
std::shared_ptr<HttpReq> req = makeHttpReq(params);
|
||||||
while(req->status() == HttpReq::REQ_IN_PROGRESS);
|
while(req->status() == HttpReq::REQ_IN_PROGRESS);
|
||||||
|
|
||||||
return parseReq(params, req);
|
return parseReq(params, req);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<HttpReq> GamesDBScraper::makeHttpReq()
|
std::shared_ptr<HttpReq> GamesDBScraper::makeHttpReq(ScraperSearchParams params)
|
||||||
{
|
{
|
||||||
return std::make_shared<HttpReq>("cdn.garcya.us", "/wp-content/uploads/2010/04/TD250.jpg");
|
std::string path = "/api/GetGame.php?";
|
||||||
|
|
||||||
|
std::string cleanName = params.nameOverride;
|
||||||
|
if(cleanName.empty())
|
||||||
|
cleanName = params.game->getBaseName();
|
||||||
|
|
||||||
|
path += "name=" + cleanName;
|
||||||
|
//platform TODO, should use some params.system get method
|
||||||
|
|
||||||
|
return std::make_shared<HttpReq>("thegamesdb.net", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<MetaDataList> GamesDBScraper::parseReq(ScraperSearchParams params, std::shared_ptr<HttpReq> req)
|
std::vector<MetaDataList> GamesDBScraper::parseReq(ScraperSearchParams params, std::shared_ptr<HttpReq> req)
|
||||||
{
|
{
|
||||||
std::vector<MetaDataList> mdl;
|
std::vector<MetaDataList> mdl;
|
||||||
|
|
||||||
MetaDataList md(params.system->getGameMDD());
|
if(req->status() != HttpReq::REQ_SUCCESS)
|
||||||
md.set("name", "JUNK RESULT #1");
|
{
|
||||||
md.set("desc", "Black triangles");
|
LOG(LogError) << "HttpReq error";
|
||||||
mdl.push_back(md);
|
return mdl;
|
||||||
|
}
|
||||||
|
|
||||||
MetaDataList md2(params.system->getGameMDD());
|
pugi::xml_document doc;
|
||||||
md2.set("name", "JUNK RESULT #2");
|
pugi::xml_parse_result parseResult = doc.load(req->getContent().c_str());
|
||||||
md2.set("desc", "Test results are very exciting. Sort of. A little. If you squint. A lot.");
|
if(!parseResult)
|
||||||
mdl.push_back(md2);
|
{
|
||||||
|
LOG(LogError) << "Error parsing XML";
|
||||||
|
return mdl;
|
||||||
|
}
|
||||||
|
|
||||||
|
pugi::xml_node data = doc.child("Data");
|
||||||
|
|
||||||
|
std::string baseImageUrl = data.child("baseImgUrl").text().get();
|
||||||
|
|
||||||
|
unsigned int resultNum = 0;
|
||||||
|
pugi::xml_node game = data.child("Game");
|
||||||
|
while(game && resultNum < 5)
|
||||||
|
{
|
||||||
|
mdl.push_back(MetaDataList(params.system->getGameMDD()));
|
||||||
|
mdl.back().set("name", game.child("GameTitle").text().get());
|
||||||
|
mdl.back().set("desc", game.child("Overview").text().get());
|
||||||
|
|
||||||
|
resultNum++;
|
||||||
|
game = game.next_sibling("Game");
|
||||||
|
}
|
||||||
|
|
||||||
return mdl;
|
return mdl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GamesDBScraper::getResultsAsync(ScraperSearchParams params, Window* window, std::function<void(std::vector<MetaDataList>)> returnFunc)
|
void GamesDBScraper::getResultsAsync(ScraperSearchParams params, Window* window, std::function<void(std::vector<MetaDataList>)> returnFunc)
|
||||||
{
|
{
|
||||||
std::shared_ptr<HttpReq> httpreq = makeHttpReq();
|
std::shared_ptr<HttpReq> httpreq = makeHttpReq(params);
|
||||||
AsyncReqComponent* req = new AsyncReqComponent(window, httpreq,
|
AsyncReqComponent* req = new AsyncReqComponent(window, httpreq,
|
||||||
[this, params, returnFunc] (std::shared_ptr<HttpReq> r)
|
[this, params, returnFunc] (std::shared_ptr<HttpReq> r)
|
||||||
{
|
{
|
||||||
|
@ -45,3 +75,4 @@ void GamesDBScraper::getResultsAsync(ScraperSearchParams params, Window* window,
|
||||||
|
|
||||||
window->pushGui(req);
|
window->pushGui(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ public:
|
||||||
void getResultsAsync(ScraperSearchParams params, Window* window, std::function<void(std::vector<MetaDataList>)> returnFunc) override;
|
void getResultsAsync(ScraperSearchParams params, Window* window, std::function<void(std::vector<MetaDataList>)> returnFunc) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<HttpReq> makeHttpReq();
|
std::shared_ptr<HttpReq> makeHttpReq(ScraperSearchParams params);
|
||||||
std::vector<MetaDataList> parseReq(ScraperSearchParams params, std::shared_ptr<HttpReq>);
|
std::vector<MetaDataList> parseReq(ScraperSearchParams params, std::shared_ptr<HttpReq>);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue