Moved some data and functions from the global to anonymous namespace.

This commit is contained in:
Leon Styhre 2021-11-13 14:27:26 +01:00
parent 187115a9e6
commit fa17d8df66
3 changed files with 232 additions and 226 deletions

View file

@ -36,96 +36,96 @@ using namespace rapidjson;
namespace
{
TheGamesDBJSONRequestResources resources;
}
const std::map<PlatformId, std::string> gamesdb_new_platformid_map{
{THREEDO, "25"},
{COMMODORE_AMIGA, "4911"},
{COMMODORE_AMIGA_CD32, "4947"},
{AMSTRAD_CPC, "4914"},
{APPLE_II, "4942"},
{ARCADE, "23"},
{ATARI_800, "4943"},
{ATARI_2600, "22"},
{ATARI_5200, "26"},
{ATARI_7800, "27"},
{ATARI_JAGUAR, "28"},
{ATARI_JAGUAR_CD, "29"},
{ATARI_LYNX, "4924"},
{ATARI_ST, "4937"},
{ATARI_XE, "30"},
{CAVESTORY, "1"},
{COLECOVISION, "31"},
{COMMODORE_64, "40"},
{COMMODORE_VIC20, "4945"},
{DAPHNE, "23"},
{INTELLIVISION, "32"},
{APPLE_MACINTOSH, "37"},
{GOOGLE_ANDROID, "4916"},
{MICROSOFT_XBOX, "14"},
{MICROSOFT_XBOX_360, "15"},
{MOONLIGHT, "1"},
{MSX, "4929"},
{MSX2, "4929"},
{MSX_TURBO_R, "4929"},
{SNK_NEO_GEO, "24"},
{SNK_NEO_GEO_CD, "24"},
{SNK_NEO_GEO_POCKET, "4922"},
{SNK_NEO_GEO_POCKET_COLOR, "4923"},
{NINTENDO_3DS, "4912"},
{NINTENDO_64, "3"},
{NINTENDO_DS, "8"},
{NINTENDO_FAMICOM, "7"},
{NINTENDO_FAMICOM_DISK_SYSTEM, "4936"},
{NINTENDO_ENTERTAINMENT_SYSTEM, "7"},
{NINTENDO_GAME_BOY, "4"},
{NINTENDO_GAME_BOY_ADVANCE, "5"},
{NINTENDO_GAME_BOY_COLOR, "41"},
{NINTENDO_GAMECUBE, "2"},
{NINTENDO_WII, "9"},
{NINTENDO_WII_U, "38"},
{NINTENDO_VIRTUAL_BOY, "4918"},
{NINTENDO_GAME_AND_WATCH, "4950"},
{NINTENDO_POKEMON_MINI, "4957"},
{NINTENDO_SATELLAVIEW, "6"},
{NINTENDO_SWITCH, "4971"},
{BANDAI_SUFAMI_TURBO, "6"},
{DOS, "1"},
{PC, "1"},
{VALVE_STEAM, "1"},
{NEC_PCFX, "4930"},
{PHILIPS_CDI, "4917"},
{SEGA_32X, "33"},
{SEGA_CD, "21"},
{SEGA_DREAMCAST, "16"},
{SEGA_GAME_GEAR, "20"},
{SEGA_GENESIS, "18"},
{SEGA_MASTER_SYSTEM, "35"},
{SEGA_MEGA_DRIVE, "36"},
{SEGA_SATURN, "17"},
{SEGA_SG1000, "4949"},
{SONY_PLAYSTATION, "10"},
{SONY_PLAYSTATION_2, "11"},
{SONY_PLAYSTATION_3, "12"},
{SONY_PLAYSTATION_4, "4919"},
{SONY_PLAYSTATION_VITA, "39"},
{SONY_PLAYSTATION_PORTABLE, "13"},
{SUPER_NINTENDO, "6"},
{SHARP_X1, "4977"},
{SHARP_X68000, "4931"},
{NEC_SUPERGRAFX, "34"},
{NEC_PC_8800, "4933"},
{NEC_PC_9800, "4934"},
{NEC_PC_ENGINE, "34"},
{NEC_PC_ENGINE_CD, "4955"},
{BANDAI_WONDERSWAN, "4925"},
{BANDAI_WONDERSWAN_COLOR, "4926"},
{SINCLAIR_ZX_SPECTRUM, "4913"},
{VIDEOPAC_ODYSSEY2, "4927"},
{VECTREX, "4939"},
{TANDY_COLOR_COMPUTER, "4941"},
{TANDY_TRS80, "4941"},
};
const std::map<PlatformId, std::string> gamesdb_new_platformid_map{
{THREEDO, "25"},
{COMMODORE_AMIGA, "4911"},
{COMMODORE_AMIGA_CD32, "4947"},
{AMSTRAD_CPC, "4914"},
{APPLE_II, "4942"},
{ARCADE, "23"},
{ATARI_800, "4943"},
{ATARI_2600, "22"},
{ATARI_5200, "26"},
{ATARI_7800, "27"},
{ATARI_JAGUAR, "28"},
{ATARI_JAGUAR_CD, "29"},
{ATARI_LYNX, "4924"},
{ATARI_ST, "4937"},
{ATARI_XE, "30"},
{CAVESTORY, "1"},
{COLECOVISION, "31"},
{COMMODORE_64, "40"},
{COMMODORE_VIC20, "4945"},
{DAPHNE, "23"},
{INTELLIVISION, "32"},
{APPLE_MACINTOSH, "37"},
{GOOGLE_ANDROID, "4916"},
{MICROSOFT_XBOX, "14"},
{MICROSOFT_XBOX_360, "15"},
{MOONLIGHT, "1"},
{MSX, "4929"},
{MSX2, "4929"},
{MSX_TURBO_R, "4929"},
{SNK_NEO_GEO, "24"},
{SNK_NEO_GEO_CD, "24"},
{SNK_NEO_GEO_POCKET, "4922"},
{SNK_NEO_GEO_POCKET_COLOR, "4923"},
{NINTENDO_3DS, "4912"},
{NINTENDO_64, "3"},
{NINTENDO_DS, "8"},
{NINTENDO_FAMICOM, "7"},
{NINTENDO_FAMICOM_DISK_SYSTEM, "4936"},
{NINTENDO_ENTERTAINMENT_SYSTEM, "7"},
{NINTENDO_GAME_BOY, "4"},
{NINTENDO_GAME_BOY_ADVANCE, "5"},
{NINTENDO_GAME_BOY_COLOR, "41"},
{NINTENDO_GAMECUBE, "2"},
{NINTENDO_WII, "9"},
{NINTENDO_WII_U, "38"},
{NINTENDO_VIRTUAL_BOY, "4918"},
{NINTENDO_GAME_AND_WATCH, "4950"},
{NINTENDO_POKEMON_MINI, "4957"},
{NINTENDO_SATELLAVIEW, "6"},
{NINTENDO_SWITCH, "4971"},
{BANDAI_SUFAMI_TURBO, "6"},
{DOS, "1"},
{PC, "1"},
{VALVE_STEAM, "1"},
{NEC_PCFX, "4930"},
{PHILIPS_CDI, "4917"},
{SEGA_32X, "33"},
{SEGA_CD, "21"},
{SEGA_DREAMCAST, "16"},
{SEGA_GAME_GEAR, "20"},
{SEGA_GENESIS, "18"},
{SEGA_MASTER_SYSTEM, "35"},
{SEGA_MEGA_DRIVE, "36"},
{SEGA_SATURN, "17"},
{SEGA_SG1000, "4949"},
{SONY_PLAYSTATION, "10"},
{SONY_PLAYSTATION_2, "11"},
{SONY_PLAYSTATION_3, "12"},
{SONY_PLAYSTATION_4, "4919"},
{SONY_PLAYSTATION_VITA, "39"},
{SONY_PLAYSTATION_PORTABLE, "13"},
{SUPER_NINTENDO, "6"},
{SHARP_X1, "4977"},
{SHARP_X68000, "4931"},
{NEC_SUPERGRAFX, "34"},
{NEC_PC_8800, "4933"},
{NEC_PC_9800, "4934"},
{NEC_PC_ENGINE, "34"},
{NEC_PC_ENGINE_CD, "4955"},
{BANDAI_WONDERSWAN, "4925"},
{BANDAI_WONDERSWAN_COLOR, "4926"},
{SINCLAIR_ZX_SPECTRUM, "4913"},
{VIDEOPAC_ODYSSEY2, "4927"},
{VECTREX, "4939"},
{TANDY_COLOR_COMPUTER, "4941"},
{TANDY_TRS80, "4941"}};
} // namespace
void thegamesdb_generate_json_scraper_requests(
const ScraperSearchParams& params,

View file

@ -26,9 +26,12 @@
#include <cmath>
#include <fstream>
const std::map<std::string, generate_scraper_requests_func> scraper_request_funcs{
{"thegamesdb", &thegamesdb_generate_json_scraper_requests},
{"screenscraper", &screenscraper_generate_scraper_requests}};
namespace
{
const std::map<std::string, generate_scraper_requests_func> scraper_request_funcs{
{"thegamesdb", &thegamesdb_generate_json_scraper_requests},
{"screenscraper", &screenscraper_generate_scraper_requests}};
}
std::unique_ptr<ScraperSearchHandle> startScraperSearch(const ScraperSearchParams& params)
{

View file

@ -23,146 +23,149 @@
using namespace PlatformIds;
// List of systems and their IDs from:
// https://www.screenscraper.fr/api/systemesListe.php?devid=xxx&devpassword=yyy&softname=zzz&output=XML
const std::map<PlatformId, unsigned short> screenscraper_platformid_map{
{THREEDO, 29},
{COMMODORE_AMIGA, 64},
{COMMODORE_AMIGA_CD32, 130},
{AMSTRAD_CPC, 65},
{AMSTRAD_GX4000, 87},
{APPLE_II, 86},
{APPLE_IIGS, 217},
{ARCADE, 75},
{ATARI_800, 43},
{ATARI_2600, 26},
{ATARI_5200, 40},
{ATARI_7800, 41},
{ATARI_JAGUAR, 27},
{ATARI_JAGUAR_CD, 171},
{ATARI_LYNX, 28},
{ATARI_ST, 42},
{ATARI_XE, 43},
{ATOMISWAVE, 53},
{BBC_MICRO, 37},
{CAVESTORY, 135},
{COLECOVISION, 48},
{COMMODORE_64, 66},
{COMMODORE_CDTV, 129},
{COMMODORE_VIC20, 73},
{DAPHNE, 49},
{INTELLIVISION, 115},
{GAMEENGINE_LUTRO, 206},
{APPLE_MACINTOSH, 146},
{GOOGLE_ANDROID, 63},
{MICROSOFT_XBOX, 32},
{MICROSOFT_XBOX_360, 33},
{MOONLIGHT, 138},
{MSX, 113},
{MSX2, 116},
{MSX_TURBO_R, 118},
{SNK_NEO_GEO, 142},
{SNK_NEO_GEO_CD, 142},
{SNK_NEO_GEO_POCKET, 25},
{SNK_NEO_GEO_POCKET_COLOR, 82},
{NINTENDO_3DS, 17},
{NINTENDO_64, 14},
{NINTENDO_DS, 15},
{NINTENDO_FAMICOM, 3},
{NINTENDO_FAMICOM_DISK_SYSTEM, 106},
{NINTENDO_ENTERTAINMENT_SYSTEM, 3},
{FAIRCHILD_CHANNELF, 80},
{NINTENDO_GAME_BOY, 9},
{NINTENDO_GAME_BOY_ADVANCE, 12},
{NINTENDO_GAME_BOY_COLOR, 10},
{NINTENDO_GAMECUBE, 13},
{NINTENDO_WII, 16},
{NINTENDO_WII_U, 18},
{NINTENDO_VIRTUAL_BOY, 11},
{NINTENDO_GAME_AND_WATCH, 52},
{NINTENDO_POKEMON_MINI, 211},
{NINTENDO_SATELLAVIEW, 107},
{NINTENDO_SWITCH, 225},
{BANDAI_SUFAMI_TURBO, 108},
{DOS, 135},
{PC, 135},
{VALVE_STEAM, 135},
{NEC_PCFX, 72},
{PHILIPS_CDI, 133},
{GAMEENGINE_OPENBOR, 214},
{TANGERINE_ORIC, 131},
{GAMEENGINE_SCUMMVM, 123},
{SEGA_32X, 19},
{SEGA_CD, 20},
{SEGA_DREAMCAST, 23},
{SEGA_GAME_GEAR, 21},
{SEGA_GENESIS, 1},
{SEGA_MASTER_SYSTEM, 2},
{SEGA_MEGA_DRIVE, 1},
{SEGA_SATURN, 22},
{SEGA_SG1000, 109},
{SHARP_X1, 220},
{SHARP_X68000, 79},
{GAMEENGINE_SOLARUS, 223},
{SONY_PLAYSTATION, 57},
{SONY_PLAYSTATION_2, 58},
{SONY_PLAYSTATION_3, 59},
{SONY_PLAYSTATION_VITA, 62},
{SONY_PLAYSTATION_PORTABLE, 61},
{SAMCOUPE, 213},
{SUPER_NINTENDO, 4},
{NEC_SUPERGRAFX, 105},
{GAMEENGINE_TIC80, 222},
{NEC_PC_8800, 221},
{NEC_PC_9800, 208},
{NEC_PC_ENGINE, 31},
{NEC_PC_ENGINE_CD, 114},
{BANDAI_WONDERSWAN, 45},
{BANDAI_WONDERSWAN_COLOR, 46},
{SINCLAIR_ZX_SPECTRUM, 76},
{SINCLAIR_ZX81_SINCLAR, 77},
{VIDEOPAC_ODYSSEY2, 104},
{VECTREX, 102},
{TANDY_TRS80, 144},
{TANDY_COLOR_COMPUTER, 144},
{SEGA_NAOMI, 56},
{THOMSON_MOTO, 141},
{UZEBOX, 216},
{SPECTRAVIDEO, 218},
{PALM_OS, 219}};
// Helper XML parsing method, finding a node-by-name recursively.
pugi::xml_node find_node_by_name_re(const pugi::xml_node& node,
const std::vector<std::string> node_names)
namespace
{
// List of systems and their IDs from:
// https://www.screenscraper.fr/api/systemesListe.php?devid=xxx&devpassword=yyy&softname=zzz&output=XML
const std::map<PlatformId, unsigned short> screenscraper_platformid_map{
{THREEDO, 29},
{COMMODORE_AMIGA, 64},
{COMMODORE_AMIGA_CD32, 130},
{AMSTRAD_CPC, 65},
{AMSTRAD_GX4000, 87},
{APPLE_II, 86},
{APPLE_IIGS, 217},
{ARCADE, 75},
{ATARI_800, 43},
{ATARI_2600, 26},
{ATARI_5200, 40},
{ATARI_7800, 41},
{ATARI_JAGUAR, 27},
{ATARI_JAGUAR_CD, 171},
{ATARI_LYNX, 28},
{ATARI_ST, 42},
{ATARI_XE, 43},
{ATOMISWAVE, 53},
{BBC_MICRO, 37},
{CAVESTORY, 135},
{COLECOVISION, 48},
{COMMODORE_64, 66},
{COMMODORE_CDTV, 129},
{COMMODORE_VIC20, 73},
{DAPHNE, 49},
{INTELLIVISION, 115},
{GAMEENGINE_LUTRO, 206},
{APPLE_MACINTOSH, 146},
{GOOGLE_ANDROID, 63},
{MICROSOFT_XBOX, 32},
{MICROSOFT_XBOX_360, 33},
{MOONLIGHT, 138},
{MSX, 113},
{MSX2, 116},
{MSX_TURBO_R, 118},
{SNK_NEO_GEO, 142},
{SNK_NEO_GEO_CD, 142},
{SNK_NEO_GEO_POCKET, 25},
{SNK_NEO_GEO_POCKET_COLOR, 82},
{NINTENDO_3DS, 17},
{NINTENDO_64, 14},
{NINTENDO_DS, 15},
{NINTENDO_FAMICOM, 3},
{NINTENDO_FAMICOM_DISK_SYSTEM, 106},
{NINTENDO_ENTERTAINMENT_SYSTEM, 3},
{FAIRCHILD_CHANNELF, 80},
{NINTENDO_GAME_BOY, 9},
{NINTENDO_GAME_BOY_ADVANCE, 12},
{NINTENDO_GAME_BOY_COLOR, 10},
{NINTENDO_GAMECUBE, 13},
{NINTENDO_WII, 16},
{NINTENDO_WII_U, 18},
{NINTENDO_VIRTUAL_BOY, 11},
{NINTENDO_GAME_AND_WATCH, 52},
{NINTENDO_POKEMON_MINI, 211},
{NINTENDO_SATELLAVIEW, 107},
{NINTENDO_SWITCH, 225},
{BANDAI_SUFAMI_TURBO, 108},
{DOS, 135},
{PC, 135},
{VALVE_STEAM, 135},
{NEC_PCFX, 72},
{PHILIPS_CDI, 133},
{GAMEENGINE_OPENBOR, 214},
{TANGERINE_ORIC, 131},
{GAMEENGINE_SCUMMVM, 123},
{SEGA_32X, 19},
{SEGA_CD, 20},
{SEGA_DREAMCAST, 23},
{SEGA_GAME_GEAR, 21},
{SEGA_GENESIS, 1},
{SEGA_MASTER_SYSTEM, 2},
{SEGA_MEGA_DRIVE, 1},
{SEGA_SATURN, 22},
{SEGA_SG1000, 109},
{SHARP_X1, 220},
{SHARP_X68000, 79},
{GAMEENGINE_SOLARUS, 223},
{SONY_PLAYSTATION, 57},
{SONY_PLAYSTATION_2, 58},
{SONY_PLAYSTATION_3, 59},
{SONY_PLAYSTATION_VITA, 62},
{SONY_PLAYSTATION_PORTABLE, 61},
{SAMCOUPE, 213},
{SUPER_NINTENDO, 4},
{NEC_SUPERGRAFX, 105},
{GAMEENGINE_TIC80, 222},
{NEC_PC_8800, 221},
{NEC_PC_9800, 208},
{NEC_PC_ENGINE, 31},
{NEC_PC_ENGINE_CD, 114},
{BANDAI_WONDERSWAN, 45},
{BANDAI_WONDERSWAN_COLOR, 46},
{SINCLAIR_ZX_SPECTRUM, 76},
{SINCLAIR_ZX81_SINCLAR, 77},
{VIDEOPAC_ODYSSEY2, 104},
{VECTREX, 102},
{TANDY_TRS80, 144},
{TANDY_COLOR_COMPUTER, 144},
{SEGA_NAOMI, 56},
{THOMSON_MOTO, 141},
{UZEBOX, 216},
{SPECTRAVIDEO, 218},
{PALM_OS, 219}};
for (const std::string& _val : node_names) {
pugi::xpath_query query_node_name((static_cast<std::string>("//") + _val).c_str());
pugi::xpath_node_set results = node.select_nodes(query_node_name);
// Helper XML parsing method, finding a node-by-name recursively. Not currently used.
// pugi::xml_node find_node_by_name_re(const pugi::xml_node& node,
// const std::vector<std::string> node_names)
// {
// for (const std::string& _val : node_names) {
// pugi::xpath_query query_node_name((static_cast<std::string>("//") +
// _val).c_str()); pugi::xpath_node_set results = node.select_nodes(query_node_name);
//
// if (results.size() > 0)
// return results.first().node();
// }
//
// return pugi::xml_node();
// }
if (results.size() > 0)
return results.first().node();
}
return pugi::xml_node();
}
// Help XML parsing method, finding an direct child XML node starting from the parent and
// filtering by an attribute value list.
pugi::xml_node find_child_by_attribute_list(const pugi::xml_node& node_parent,
const std::string& node_name,
const std::string& attribute_name,
const std::vector<std::string> attribute_values)
{
for (auto _val : attribute_values) {
for (pugi::xml_node node : node_parent.children(node_name.c_str())) {
if (node.attribute(attribute_name.c_str()).value() == _val)
return node;
// Help XML parsing method, finding an direct child XML node starting from the parent and
// filtering by an attribute value list.
pugi::xml_node find_child_by_attribute_list(const pugi::xml_node& node_parent,
const std::string& node_name,
const std::string& attribute_name,
const std::vector<std::string> attribute_values)
{
for (auto _val : attribute_values) {
for (pugi::xml_node node : node_parent.children(node_name.c_str())) {
if (node.attribute(attribute_name.c_str()).value() == _val)
return node;
}
}
return pugi::xml_node(nullptr);
}
return pugi::xml_node(nullptr);
}
} // namespace
void screenscraper_generate_scraper_requests(const ScraperSearchParams& params,
std::queue<std::unique_ptr<ScraperRequest>>& requests,