mirror of
https://github.com/Sude-/lgogdownloader.git
synced 2024-11-20 11:49:17 +01:00
Fix listing/downloading free games using "--game free"
This commit is contained in:
parent
795a131c15
commit
c9668c66d2
@ -1277,8 +1277,26 @@ std::vector<std::string> Downloader::getGames()
|
|||||||
// Get list of free games
|
// Get list of free games
|
||||||
std::vector<std::string> Downloader::getFreeGames()
|
std::vector<std::string> Downloader::getFreeGames()
|
||||||
{
|
{
|
||||||
|
Json::Value root;
|
||||||
|
Json::Reader *jsonparser = new Json::Reader;
|
||||||
std::vector<std::string> games;
|
std::vector<std::string> games;
|
||||||
std::string html = this->getResponse("https://secure.gog.com/catalogue/ajax?a=getGames&tab=all_genres&genre=all_genres&price=0&order=alph&publisher=&releaseDate=&availability=&gameMode=&rating=&search=&sort=vote&system=&language=&mixPage=1");
|
std::string json = this->getResponse("https://secure.gog.com/games/ajax?a=search&f={\"price\":[\"free\"]}&p=1&t=all");
|
||||||
|
|
||||||
|
// Parse JSON
|
||||||
|
if (!jsonparser->parse(json, root))
|
||||||
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
|
std::cerr << "DEBUG INFO (Downloader::getFreeGames)" << std::endl << json << std::endl;
|
||||||
|
#endif
|
||||||
|
std::cout << jsonparser->getFormatedErrorMessages();
|
||||||
|
delete jsonparser;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
#ifdef DEBUG
|
||||||
|
std::cerr << "DEBUG INFO (Downloader::getFreeGames)" << std::endl << root << std::endl;
|
||||||
|
#endif
|
||||||
|
std::string html = root["result"]["html"].asString();
|
||||||
|
delete jsonparser;
|
||||||
|
|
||||||
// Parse HTML to get game names
|
// Parse HTML to get game names
|
||||||
htmlcxx::HTML::ParserDom parser;
|
htmlcxx::HTML::ParserDom parser;
|
||||||
@ -1287,14 +1305,14 @@ std::vector<std::string> Downloader::getFreeGames()
|
|||||||
tree<htmlcxx::HTML::Node>::iterator end = dom.end();
|
tree<htmlcxx::HTML::Node>::iterator end = dom.end();
|
||||||
for (; it != end; ++it)
|
for (; it != end; ++it)
|
||||||
{
|
{
|
||||||
if (it->tagName()=="a")
|
if (it->tagName()=="span")
|
||||||
{
|
{
|
||||||
it->parseAttributes();
|
it->parseAttributes();
|
||||||
std::string classname = it->attribute("class").second;
|
std::string classname = it->attribute("class").second;
|
||||||
if (classname=="game-title-link")
|
if (classname=="gog-price game-owned")
|
||||||
{
|
{
|
||||||
std::string game = it->attribute("href").second;
|
// Game name is contained in data-gameindex attribute
|
||||||
game.assign(game.begin()+game.find_last_of("/")+1,game.end());
|
std::string game = it->attribute("data-gameindex").second;
|
||||||
if (!game.empty())
|
if (!game.empty())
|
||||||
games.push_back(game);
|
games.push_back(game);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user