2022-06-15 19:22:12 +00:00
|
|
|
/*
|
|
|
|
Copyright 2022 flyinghead
|
|
|
|
|
|
|
|
This file is part of Flycast.
|
|
|
|
|
|
|
|
Flycast is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Flycast is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Flycast. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include "scraper.h"
|
|
|
|
#include "json.hpp"
|
|
|
|
|
2023-01-21 15:59:38 +00:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2022-06-15 19:22:12 +00:00
|
|
|
using namespace nlohmann;
|
|
|
|
|
|
|
|
class TheGamesDb : public Scraper
|
|
|
|
{
|
|
|
|
public:
|
2022-06-20 16:07:06 +00:00
|
|
|
bool initialize(const std::string& saveDirectory) override;
|
|
|
|
void scrape(GameBoxart& item) override;
|
2022-06-23 20:06:50 +00:00
|
|
|
void scrape(std::vector<GameBoxart>& items) override;
|
2022-06-15 19:22:12 +00:00
|
|
|
~TheGamesDb();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void fetchPlatforms();
|
2022-06-20 16:07:06 +00:00
|
|
|
bool fetchGameInfo(GameBoxart& item, const std::string& url, const std::string& diskId = "");
|
2022-06-15 19:22:12 +00:00
|
|
|
std::string makeUrl(const std::string& endpoint);
|
|
|
|
void copyFile(const std::string& from, const std::string& to);
|
2022-06-23 20:06:50 +00:00
|
|
|
json httpGet(const std::string& url);
|
2022-06-20 16:07:06 +00:00
|
|
|
void parseBoxart(GameBoxart& item, const json& j, int gameId);
|
2022-06-23 20:06:50 +00:00
|
|
|
void fetchByUids(std::vector<GameBoxart>& items);
|
|
|
|
void fetchByName(GameBoxart& item);
|
|
|
|
bool parseGameInfo(const json& gameArray, const json& boxartArray, GameBoxart& item, const std::string& diskId);
|
2022-06-15 19:22:12 +00:00
|
|
|
|
2022-06-23 20:06:50 +00:00
|
|
|
int dreamcastPlatformId = 0;
|
|
|
|
int arcadePlatformId = 0;
|
2022-06-15 19:22:12 +00:00
|
|
|
double blackoutPeriod = 0.0;
|
|
|
|
|
|
|
|
std::map<std::string, std::string> boxartCache; // key: url, value: local file path
|
|
|
|
};
|