comparison src/services/anilist.cc @ 286:53e3c015a973

anime: initial cross-service support currently the Kitsu and MAL services don't work when chosen in the GUI. This is because they haven't been implemented yet :)
author Paper <paper@paper.us.eu.org>
date Wed, 08 May 2024 16:44:27 -0400
parents e66ffc338d82
children 9a88e1725fd2
comparison
equal deleted inserted replaced
285:65df2813d0de 286:53e3c015a973
24 using namespace nlohmann::literals::json_literals; 24 using namespace nlohmann::literals::json_literals;
25 25
26 namespace Services { 26 namespace Services {
27 namespace AniList { 27 namespace AniList {
28 28
29 constexpr int CLIENT_ID = 13706; 29 static constexpr int CLIENT_ID = 13706;
30 30
31 class Account { 31 class Account {
32 public: 32 public:
33 int UserId() const { return session.config.auth.anilist.user_id; } 33 int UserId() const { return session.config.auth.anilist.user_id; }
34 void SetUserId(const int id) { session.config.auth.anilist.user_id = id; } 34 void SetUserId(const int id) { session.config.auth.anilist.user_id = id; }
35 35
36 std::string AuthToken() const { return session.config.auth.anilist.auth_token; } 36 std::string AuthToken() const { return session.config.auth.anilist.auth_token; }
37 void SetAuthToken(std::string const& auth_token) { session.config.auth.anilist.auth_token = auth_token; } 37 void SetAuthToken(const std::string& auth_token) { session.config.auth.anilist.auth_token = auth_token; }
38 38
39 bool Authenticated() const { return !AuthToken().empty(); } 39 bool Authenticated() const { return !AuthToken().empty(); }
40 bool IsValid() const { return UserId() && Authenticated(); } 40 bool IsValid() const { return UserId() && Authenticated(); }
41 }; 41 };
42 42
128 if (!id) 128 if (!id)
129 return 0; 129 return 0;
130 130
131 Anime::Anime& anime = Anime::db.items[id]; 131 Anime::Anime& anime = Anime::db.items[id];
132 anime.SetId(id); 132 anime.SetId(id);
133 anime.SetServiceId(Anime::Service::AniList, Strings::ToUtf8String(id));
134 anime.SetServiceId(Anime::Service::MyAnimeList, Strings::ToUtf8String(JSON::GetNumber(json, "/id_mal"_json_pointer)));
133 135
134 ParseTitle(json.at("/title"_json_pointer), anime); 136 ParseTitle(json.at("/title"_json_pointer), anime);
135 137
136 anime.SetEpisodes(JSON::GetNumber(json, "/episodes"_json_pointer, 0)); 138 anime.SetEpisodes(JSON::GetNumber(json, "/episodes"_json_pointer, 0));
137 anime.SetFormat(Translate::AniList::ToSeriesFormat(JSON::GetString<std::string>(json, "/format"_json_pointer, ""))); 139 anime.SetFormat(Translate::AniList::ToSeriesFormat(JSON::GetString<std::string>(json, "/format"_json_pointer, "")));
264 " media (search: $search, type: ANIME) {\n" 266 " media (search: $search, type: ANIME) {\n"
265 " coverImage {\n" 267 " coverImage {\n"
266 " large\n" 268 " large\n"
267 " }\n" 269 " }\n"
268 " id\n" 270 " id\n"
271 " id_mal\n"
269 " title {\n" 272 " title {\n"
270 " romaji\n" 273 " romaji\n"
271 " english\n" 274 " english\n"
272 " native\n" 275 " native\n"
273 " }\n" 276 " }\n"