2013-09-16 19:53:24 +00:00
|
|
|
#include "GamesDBScraper.h"
|
2014-03-12 03:00:08 +00:00
|
|
|
#include "../components/ScraperSearchComponent.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"
|
2014-03-12 03:00:08 +00:00
|
|
|
#include "../Settings.h"
|
2013-10-10 00:50:42 +00:00
|
|
|
#include <boost/assign.hpp>
|
2013-09-16 19:53:24 +00:00
|
|
|
|
2013-10-03 20:58:09 +00:00
|
|
|
const char* GamesDBScraper::getName() { return "TheGamesDB"; }
|
|
|
|
|
|
2013-10-10 00:50:42 +00:00
|
|
|
using namespace PlatformIds;
|
|
|
|
|
const std::map<PlatformId, const char*> gamesdb_platformid_map = boost::assign::map_list_of
|
|
|
|
|
(THREEDO, "3DO")
|
|
|
|
|
(AMIGA, "Amiga")
|
|
|
|
|
(ARCADE, "Arcade")
|
|
|
|
|
(ATARI_2600, "Atari 2600")
|
|
|
|
|
(ATARI_5200, "Atari 5200")
|
|
|
|
|
(ATARI_7800, "Atari 7800")
|
|
|
|
|
(ATARI_JAGUAR, "Atari Jaguar")
|
|
|
|
|
(ATARI_JAGUAR_CD, "Atari Jaguar CD")
|
|
|
|
|
(ATARI_XE, "Atari XE")
|
|
|
|
|
(COLECOVISION, "Colecovision")
|
|
|
|
|
(COMMODORE_64, "Commodore 64")
|
|
|
|
|
(INTELLIVISION, "Intellivision")
|
|
|
|
|
(MAC_OS, "Mac OS")
|
|
|
|
|
(XBOX, "Microsoft Xbox")
|
|
|
|
|
(XBOX_360, "Microsoft Xbox 360")
|
|
|
|
|
(NEOGEO, "NeoGeo")
|
|
|
|
|
(NINTENDO_3DS, "Nintendo 3DS")
|
|
|
|
|
(NINTENDO_64, "Nintendo 64")
|
|
|
|
|
(NINTENDO_DS, "Nintendo DS")
|
|
|
|
|
(NINTENDO_ENTERTAINMENT_SYSTEM, "Nintendo Entertainment System (NES)")
|
|
|
|
|
(GAME_BOY, "Nintendo Game Boy")
|
|
|
|
|
(GAME_BOY_ADVANCE, "Nintendo Game Boy Advance")
|
|
|
|
|
(GAME_BOY_COLOR, "Nintendo Game Boy Color")
|
|
|
|
|
(NINTENDO_GAMECUBE, "Nintendo GameCube")
|
|
|
|
|
(NINTENDO_WII, "Nintendo Wii")
|
|
|
|
|
(NINTENDO_WII_U, "Nintendo Wii U")
|
|
|
|
|
(PC, "PC")
|
|
|
|
|
(SEGA_32X, "Sega 32X")
|
|
|
|
|
(SEGA_CD, "Sega CD")
|
|
|
|
|
(SEGA_DREAMCAST, "Sega Dreamcast")
|
|
|
|
|
(SEGA_GAME_GEAR, "Sega Game Gear")
|
|
|
|
|
(SEGA_GENESIS, "Sega Genesis")
|
|
|
|
|
(SEGA_MASTER_SYSTEM, "Sega Master System")
|
|
|
|
|
(SEGA_MEGA_DRIVE, "Sega Mega Drive")
|
|
|
|
|
(SEGA_SATURN, "Sega Saturn")
|
|
|
|
|
(PLAYSTATION, "Sony Playstation")
|
|
|
|
|
(PLAYSTATION_2, "Sony Playstation 2")
|
|
|
|
|
(PLAYSTATION_3, "Sony Playstation 3")
|
|
|
|
|
(PLAYSTATION_VITA, "Sony Playstation Vita")
|
|
|
|
|
(PLAYSTATION_PORTABLE, "Sony PSP")
|
|
|
|
|
(SUPER_NINTENDO, "Super Nintendo (SNES)")
|
|
|
|
|
(TURBOGRAFX_16, "TurboGrafx 16");
|
|
|
|
|
|
|
|
|
|
|
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-11-06 01:41:49 +00:00
|
|
|
cleanName = getCleanFileName(params.game->getPath());
|
2013-09-20 19:55:44 +00:00
|
|
|
|
2013-09-24 07:02:14 +00:00
|
|
|
path += "name=" + HttpReq::urlEncode(cleanName);
|
2013-10-10 00:50:42 +00:00
|
|
|
|
|
|
|
|
if(params.system->getPlatformId() != PLATFORM_UNKNOWN)
|
|
|
|
|
{
|
|
|
|
|
path += "&platform=";
|
|
|
|
|
path += HttpReq::urlEncode(gamesdb_platformid_map.at(params.system->getPlatformId()));
|
|
|
|
|
}
|
2013-09-20 19:55:44 +00:00
|
|
|
|
2013-10-10 18:11:01 +00:00
|
|
|
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
|
|
|
{
|
2013-11-04 01:54:13 +00:00
|
|
|
mdl.push_back(MetaDataList(GAME_METADATA));
|
2013-09-20 19:55:44 +00:00
|
|
|
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);
|
|
|
|
|
|
2014-01-19 23:22:26 +00:00
|
|
|
mdl.back().set("developer", game.child("Developer").text().get());
|
|
|
|
|
mdl.back().set("publisher", game.child("Publisher").text().get());
|
|
|
|
|
mdl.back().set("genre", game.child("Genres").first_child().text().get());
|
|
|
|
|
mdl.back().set("players", game.child("Players").text().get());
|
|
|
|
|
|
2013-10-16 22:05:02 +00:00
|
|
|
if(Settings::getInstance()->getBool("ScrapeRatings") && game.child("Rating"))
|
|
|
|
|
{
|
|
|
|
|
float ratingVal = (game.child("Rating").text().as_int() / 10.0f);
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
ss << ratingVal;
|
|
|
|
|
mdl.back().set("rating", ss.str());
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|