2013-09-16 19:53:24 +00:00
|
|
|
#include "GamesDBScraper.h"
|
2013-09-24 04:58:59 +00:00
|
|
|
#include "../components/GuiGameScraper.h"
|
2013-09-17 21:50:49 +00:00
|
|
|
#include "../components/AsyncReqComponent.h"
|
2013-09-19 23:41:14 +00:00
|
|
|
#include "../Log.h"
|
2013-09-20 19:55:44 +00:00
|
|
|
#include "../pugiXML/pugixml.hpp"
|
2013-09-28 17:51:16 +00:00
|
|
|
#include "../MetaData.h"
|
2013-09-16 19:53:24 +00:00
|
|
|
|
2013-09-20 19:55:44 +00:00
|
|
|
std::shared_ptr<HttpReq> GamesDBScraper::makeHttpReq(ScraperSearchParams params)
|
2013-09-17 21:50:49 +00:00
|
|
|
{
|
2013-09-20 19:55:44 +00:00
|
|
|
std::string path = "/api/GetGame.php?";
|
|
|
|
|
|
|
|
std::string cleanName = params.nameOverride;
|
|
|
|
if(cleanName.empty())
|
2013-09-24 05:20:53 +00:00
|
|
|
cleanName = params.game->getCleanName();
|
2013-09-20 19:55:44 +00:00
|
|
|
|
2013-09-24 07:02:14 +00:00
|
|
|
path += "name=" + HttpReq::urlEncode(cleanName);
|
2013-09-20 19:55:44 +00:00
|
|
|
//platform TODO, should use some params.system get method
|
|
|
|
|
|
|
|
return std::make_shared<HttpReq>("thegamesdb.net", path);
|
2013-09-17 21:50:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<MetaDataList> GamesDBScraper::parseReq(ScraperSearchParams params, std::shared_ptr<HttpReq> req)
|
|
|
|
{
|
|
|
|
std::vector<MetaDataList> mdl;
|
|
|
|
|
2013-09-20 19:55:44 +00:00
|
|
|
if(req->status() != HttpReq::REQ_SUCCESS)
|
|
|
|
{
|
|
|
|
LOG(LogError) << "HttpReq error";
|
|
|
|
return mdl;
|
|
|
|
}
|
|
|
|
|
|
|
|
pugi::xml_document doc;
|
|
|
|
pugi::xml_parse_result parseResult = doc.load(req->getContent().c_str());
|
|
|
|
if(!parseResult)
|
|
|
|
{
|
|
|
|
LOG(LogError) << "Error parsing XML";
|
|
|
|
return mdl;
|
|
|
|
}
|
2013-09-19 23:41:14 +00:00
|
|
|
|
2013-09-20 19:55:44 +00:00
|
|
|
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");
|
2013-09-24 04:58:59 +00:00
|
|
|
while(game && resultNum < MAX_SCRAPER_RESULTS)
|
2013-09-20 19:55:44 +00:00
|
|
|
{
|
|
|
|
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());
|
2013-09-28 17:51:16 +00:00
|
|
|
|
|
|
|
boost::posix_time::ptime rd = string_to_ptime(game.child("ReleaseDate").text().get(), "%m/%d/%Y");
|
|
|
|
mdl.back().setTime("releasedate", rd);
|
|
|
|
|
2013-09-20 23:55:05 +00:00
|
|
|
pugi::xml_node images = game.child("Images");
|
|
|
|
|
|
|
|
if(images)
|
|
|
|
{
|
|
|
|
pugi::xml_node art = images.find_child_by_attribute("boxart", "side", "front");
|
|
|
|
|
|
|
|
if(art)
|
|
|
|
{
|
|
|
|
mdl.back().set("thumbnail", baseImageUrl + art.attribute("thumb").as_string());
|
|
|
|
mdl.back().set("image", baseImageUrl + art.text().get());
|
|
|
|
}
|
|
|
|
}
|
2013-09-20 19:55:44 +00:00
|
|
|
|
|
|
|
resultNum++;
|
|
|
|
game = game.next_sibling("Game");
|
|
|
|
}
|
2013-09-19 23:41:14 +00:00
|
|
|
|
2013-09-17 21:50:49 +00:00
|
|
|
return mdl;
|
|
|
|
}
|