Mercurial > minori
annotate src/services/anilist.cc @ 322:c32467cd06bb
core/strings: add Strings::Translate function as tr() -> ToUtf8String
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Wed, 12 Jun 2024 22:15:53 -0400 |
parents | 8141f409d52c |
children | 1686fac290c5 |
rev | line source |
---|---|
9 | 1 #include "services/anilist.h" |
2 #include "core/anime.h" | |
10 | 3 #include "core/anime_db.h" |
304
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
4 #include "core/date.h" |
9 | 5 #include "core/config.h" |
76 | 6 #include "core/http.h" |
9 | 7 #include "core/json.h" |
8 #include "core/session.h" | |
9 #include "core/strings.h" | |
15 | 10 #include "gui/translate/anilist.h" |
187
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
185
diff
changeset
|
11 |
258 | 12 #include <QByteArray> |
187
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
185
diff
changeset
|
13 #include <QDate> |
9 | 14 #include <QDesktopServices> |
15 #include <QInputDialog> | |
16 #include <QLineEdit> | |
17 #include <QMessageBox> | |
10 | 18 #include <QUrl> |
187
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
185
diff
changeset
|
19 |
9 | 20 #include <chrono> |
21 #include <exception> | |
291 | 22 #include <string_view> |
175 | 23 |
24 #include <iostream> | |
25 | |
317
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
26 /* This file really sucks because it was made when I was first |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
27 * really "learning" C++ */ |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
28 |
64 | 29 using namespace nlohmann::literals::json_literals; |
11 | 30 |
63 | 31 namespace Services { |
32 namespace AniList { | |
9 | 33 |
291 | 34 static constexpr std::string_view CLIENT_ID = "13706"; |
304
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
35 #define MEDIA_FIELDS \ |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
36 "coverImage {\n" \ |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
37 " large\n" \ |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
38 "}\n" \ |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
39 "id\n" \ |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
40 "title {\n" \ |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
41 " romaji\n" \ |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
42 " english\n" \ |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
43 " native\n" \ |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
44 "}\n" \ |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
45 "format\n" \ |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
46 "status\n" \ |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
47 "averageScore\n" \ |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
48 "season\n" \ |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
49 "startDate {\n" \ |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
50 " year\n" \ |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
51 " month\n" \ |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
52 " day\n" \ |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
53 "}\n" \ |
321
8141f409d52c
services/anilist: fix getting producers
Paper <paper@paper.us.eu.org>
parents:
320
diff
changeset
|
54 "studios {\n" \ |
8141f409d52c
services/anilist: fix getting producers
Paper <paper@paper.us.eu.org>
parents:
320
diff
changeset
|
55 " edges {\n" \ |
8141f409d52c
services/anilist: fix getting producers
Paper <paper@paper.us.eu.org>
parents:
320
diff
changeset
|
56 " node {\n" \ |
8141f409d52c
services/anilist: fix getting producers
Paper <paper@paper.us.eu.org>
parents:
320
diff
changeset
|
57 " name\n" \ |
8141f409d52c
services/anilist: fix getting producers
Paper <paper@paper.us.eu.org>
parents:
320
diff
changeset
|
58 " }\n" \ |
8141f409d52c
services/anilist: fix getting producers
Paper <paper@paper.us.eu.org>
parents:
320
diff
changeset
|
59 " }\n" \ |
8141f409d52c
services/anilist: fix getting producers
Paper <paper@paper.us.eu.org>
parents:
320
diff
changeset
|
60 "}\n" \ |
304
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
61 "genres\n" \ |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
62 "episodes\n" \ |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
63 "duration\n" \ |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
64 "synonyms\n" \ |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
65 "description(asHtml: false)\n" |
185
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
184
diff
changeset
|
66 |
317
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
67 /* FIXME: why is this here */ |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
68 |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
69 static struct { |
258 | 70 int UserId() const { return session.config.auth.anilist.user_id; } |
71 void SetUserId(const int id) { session.config.auth.anilist.user_id = id; } | |
9 | 72 |
258 | 73 std::string AuthToken() const { return session.config.auth.anilist.auth_token; } |
286
53e3c015a973
anime: initial cross-service support
Paper <paper@paper.us.eu.org>
parents:
284
diff
changeset
|
74 void SetAuthToken(const std::string& auth_token) { session.config.auth.anilist.auth_token = auth_token; } |
9 | 75 |
317
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
76 bool IsValid() const { return UserId() && !AuthToken().empty(); } |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
77 } account; |
9 | 78 |
291 | 79 static std::string SendRequest(const std::string& data) { |
76 | 80 std::vector<std::string> headers = {"Authorization: Bearer " + account.AuthToken(), "Accept: application/json", |
258 | 81 "Content-Type: application/json"}; |
291 | 82 return Strings::ToUtf8String(HTTP::Request("https://graphql.anilist.co", headers, data, HTTP::Type::Post)); |
9 | 83 } |
84 | |
315
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
85 static bool SendJSONRequest(const nlohmann::json& data, nlohmann::json& out) { |
175 | 86 std::string request = SendRequest(data.dump()); |
87 if (request.empty()) { | |
315
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
88 session.SetStatusBar("AniList: JSON request returned an empty result!"); |
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
89 return false; |
175 | 90 } |
91 | |
315
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
92 out = nlohmann::json::parse(request, nullptr, false); |
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
93 if (out.is_discarded()) { |
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
94 session.SetStatusBar("AniList: Failed to parse request JSON!"); |
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
95 return false; |
175 | 96 } |
97 | |
315
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
98 if (out.contains("/errors"_json_pointer) && out.at("/errors"_json_pointer).is_array()) { |
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
99 for (const auto& error : out.at("/errors"_json_pointer)) |
317
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
100 std::cerr << "AniList: Received an error in response: " |
258 | 101 << JSON::GetString<std::string>(error, "/message"_json_pointer, "") << std::endl; |
175 | 102 |
315
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
103 session.SetStatusBar("AniList: Received an error in response!"); |
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
104 return false; |
175 | 105 } |
106 | |
315
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
107 return true; |
175 | 108 } |
109 | |
291 | 110 static void ParseListStatus(std::string status, Anime::Anime& anime) { |
187
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
185
diff
changeset
|
111 static const std::unordered_map<std::string, Anime::ListStatus> map = { |
279 | 112 {"CURRENT", Anime::ListStatus::Current }, |
113 {"PLANNING", Anime::ListStatus::Planning }, | |
114 {"COMPLETED", Anime::ListStatus::Completed}, | |
115 {"DROPPED", Anime::ListStatus::Dropped }, | |
116 {"PAUSED", Anime::ListStatus::Paused } | |
258 | 117 }; |
9 | 118 |
15 | 119 if (status == "REPEATING") { |
120 anime.SetUserIsRewatching(true); | |
279 | 121 anime.SetUserStatus(Anime::ListStatus::Current); |
15 | 122 return; |
123 } | |
9 | 124 |
47
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
44
diff
changeset
|
125 if (map.find(status) == map.end()) { |
279 | 126 anime.SetUserStatus(Anime::ListStatus::NotInList); |
15 | 127 return; |
128 } | |
9 | 129 |
187
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
185
diff
changeset
|
130 anime.SetUserStatus(map.at(status)); |
15 | 131 } |
9 | 132 |
291 | 133 static std::string ListStatusToString(const Anime::Anime& anime) { |
279 | 134 if (anime.GetUserIsRewatching() && anime.GetUserStatus() == Anime::ListStatus::Current) |
15 | 135 return "REWATCHING"; |
136 | |
70
64e5f427c6a2
services/anilist: remove unordered_map usage for enum classes
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
137 switch (anime.GetUserStatus()) { |
279 | 138 case Anime::ListStatus::Planning: return "PLANNING"; |
139 case Anime::ListStatus::Completed: return "COMPLETED"; | |
140 case Anime::ListStatus::Dropped: return "DROPPED"; | |
141 case Anime::ListStatus::Paused: return "PAUSED"; | |
76 | 142 default: break; |
70
64e5f427c6a2
services/anilist: remove unordered_map usage for enum classes
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
143 } |
64e5f427c6a2
services/anilist: remove unordered_map usage for enum classes
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
144 return "CURRENT"; |
15 | 145 } |
9 | 146 |
291 | 147 static void ParseTitle(const nlohmann::json& json, Anime::Anime& anime) { |
305
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
304
diff
changeset
|
148 static const std::unordered_map<Anime::TitleLanguage, nlohmann::json::json_pointer> map = { |
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
304
diff
changeset
|
149 {Anime::TitleLanguage::Native, "/native"_json_pointer}, |
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
304
diff
changeset
|
150 {Anime::TitleLanguage::English, "/english"_json_pointer}, |
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
304
diff
changeset
|
151 {Anime::TitleLanguage::Romaji, "/romaji"_json_pointer}, |
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
304
diff
changeset
|
152 }; |
284
e66ffc338d82
anime: refactor title structure to a map
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
153 |
305
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
304
diff
changeset
|
154 for (const auto& [language, ptr] : map) |
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
304
diff
changeset
|
155 if (json.contains(ptr) && json[ptr].is_string()) |
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
304
diff
changeset
|
156 anime.SetTitle(language, json[ptr]); |
9 | 157 } |
158 | |
291 | 159 static int ParseMediaJson(const nlohmann::json& json) { |
319
d928ec7b6a0d
services/kitsu: implement GetAnimeList()
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
160 if (!json.contains("/id"_json_pointer) || !json["/id"_json_pointer].is_number()) { |
d928ec7b6a0d
services/kitsu: implement GetAnimeList()
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
161 session.SetStatusBar("AniList: Failed to parse anime object!"); |
9 | 162 return 0; |
319
d928ec7b6a0d
services/kitsu: implement GetAnimeList()
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
163 } |
175 | 164 |
317
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
165 std::string service_id = Strings::ToUtf8String(json["/id"_json_pointer].get<int>()); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
166 |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
167 int id = Anime::db.LookupServiceIdOrUnused(Anime::Service::AniList, service_id); |
319
d928ec7b6a0d
services/kitsu: implement GetAnimeList()
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
168 if (!id) { |
d928ec7b6a0d
services/kitsu: implement GetAnimeList()
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
169 session.SetStatusBar("AniList: Failed to parse anime object!"); |
d928ec7b6a0d
services/kitsu: implement GetAnimeList()
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
170 return 0; |
d928ec7b6a0d
services/kitsu: implement GetAnimeList()
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
171 } |
317
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
172 |
9 | 173 Anime::Anime& anime = Anime::db.items[id]; |
174 anime.SetId(id); | |
317
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
175 anime.SetServiceId(Anime::Service::AniList, service_id); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
176 |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
177 if (json.contains("/id_mal"_json_pointer)) |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
178 anime.SetServiceId(Anime::Service::MyAnimeList, json["/id_mal"_json_pointer].get<std::string>()); |
9 | 179 |
11 | 180 ParseTitle(json.at("/title"_json_pointer), anime); |
9 | 181 |
175 | 182 anime.SetEpisodes(JSON::GetNumber(json, "/episodes"_json_pointer, 0)); |
183 anime.SetFormat(Translate::AniList::ToSeriesFormat(JSON::GetString<std::string>(json, "/format"_json_pointer, ""))); | |
9 | 184 |
258 | 185 anime.SetAiringStatus( |
186 Translate::AniList::ToSeriesStatus(JSON::GetString<std::string>(json, "/status"_json_pointer, ""))); | |
9 | 187 |
175 | 188 anime.SetAirDate(Date(json["/startDate"_json_pointer])); |
9 | 189 |
175 | 190 anime.SetPosterUrl(JSON::GetString<std::string>(json, "/coverImage/large"_json_pointer, "")); |
66
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
65
diff
changeset
|
191 |
175 | 192 anime.SetAudienceScore(JSON::GetNumber(json, "/averageScore"_json_pointer, 0)); |
279 | 193 // anime.SetSeason(Translate::AniList::ToSeriesSeason(JSON::GetString<std::string>(json, "/season"_json_pointer, ""))); |
175 | 194 anime.SetDuration(JSON::GetNumber(json, "/duration"_json_pointer, 0)); |
260
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
195 |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
196 std::string synopsis = JSON::GetString<std::string>(json, "/description"_json_pointer, ""); |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
197 Strings::TextifySynopsis(synopsis); |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
198 anime.SetSynopsis(synopsis); |
9 | 199 |
175 | 200 anime.SetGenres(JSON::GetArray<std::vector<std::string>>(json, "/genres"_json_pointer, {})); |
201 anime.SetTitleSynonyms(JSON::GetArray<std::vector<std::string>>(json, "/synonyms"_json_pointer, {})); | |
202 | |
321
8141f409d52c
services/anilist: fix getting producers
Paper <paper@paper.us.eu.org>
parents:
320
diff
changeset
|
203 { |
8141f409d52c
services/anilist: fix getting producers
Paper <paper@paper.us.eu.org>
parents:
320
diff
changeset
|
204 std::vector<std::string> producers; |
8141f409d52c
services/anilist: fix getting producers
Paper <paper@paper.us.eu.org>
parents:
320
diff
changeset
|
205 |
8141f409d52c
services/anilist: fix getting producers
Paper <paper@paper.us.eu.org>
parents:
320
diff
changeset
|
206 if (json.contains("/studios/edges"_json_pointer) && json["/studios/edges"_json_pointer].is_array()) |
8141f409d52c
services/anilist: fix getting producers
Paper <paper@paper.us.eu.org>
parents:
320
diff
changeset
|
207 for (const auto& edge : json["/studios/edges"_json_pointer]) |
8141f409d52c
services/anilist: fix getting producers
Paper <paper@paper.us.eu.org>
parents:
320
diff
changeset
|
208 if (edge.contains("/node/name"_json_pointer) && edge["/node/name"_json_pointer].is_string()) |
8141f409d52c
services/anilist: fix getting producers
Paper <paper@paper.us.eu.org>
parents:
320
diff
changeset
|
209 producers.push_back(edge["/node/name"_json_pointer].get<std::string>()); |
8141f409d52c
services/anilist: fix getting producers
Paper <paper@paper.us.eu.org>
parents:
320
diff
changeset
|
210 |
8141f409d52c
services/anilist: fix getting producers
Paper <paper@paper.us.eu.org>
parents:
320
diff
changeset
|
211 anime.SetProducers(producers); |
8141f409d52c
services/anilist: fix getting producers
Paper <paper@paper.us.eu.org>
parents:
320
diff
changeset
|
212 } |
8141f409d52c
services/anilist: fix getting producers
Paper <paper@paper.us.eu.org>
parents:
320
diff
changeset
|
213 |
10 | 214 return id; |
9 | 215 } |
216 | |
291 | 217 static int ParseListItem(const nlohmann::json& json) { |
319
d928ec7b6a0d
services/kitsu: implement GetAnimeList()
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
218 int id = ParseMediaJson(json["/media"_json_pointer]); |
317
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
219 if (!id) |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
220 return 0; |
10 | 221 |
222 Anime::Anime& anime = Anime::db.items[id]; | |
223 | |
224 anime.AddToUserList(); | |
9 | 225 |
175 | 226 anime.SetUserScore(JSON::GetNumber(json, "/score"_json_pointer, 0)); |
227 anime.SetUserProgress(JSON::GetNumber(json, "/progress"_json_pointer, 0)); | |
228 ParseListStatus(JSON::GetString<std::string>(json, "/status"_json_pointer, ""), anime); | |
229 anime.SetUserNotes(JSON::GetString<std::string>(json, "/notes"_json_pointer, "")); | |
9 | 230 |
175 | 231 anime.SetUserDateStarted(Date(json["/startedAt"_json_pointer])); |
232 anime.SetUserDateCompleted(Date(json["/completedAt"_json_pointer])); | |
9 | 233 |
175 | 234 anime.SetUserTimeUpdated(JSON::GetNumber(json, "/updatedAt"_json_pointer, 0)); |
10 | 235 |
236 return id; | |
9 | 237 } |
238 | |
319
d928ec7b6a0d
services/kitsu: implement GetAnimeList()
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
239 static bool ParseList(const nlohmann::json& json) { |
d928ec7b6a0d
services/kitsu: implement GetAnimeList()
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
240 bool success = true; |
d928ec7b6a0d
services/kitsu: implement GetAnimeList()
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
241 |
317
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
242 for (const auto& entry : json["entries"].items()) |
319
d928ec7b6a0d
services/kitsu: implement GetAnimeList()
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
243 if (!ParseListItem(entry.value())) |
d928ec7b6a0d
services/kitsu: implement GetAnimeList()
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
244 success = false; |
317
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
245 |
319
d928ec7b6a0d
services/kitsu: implement GetAnimeList()
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
246 return success; |
9 | 247 } |
248 | |
10 | 249 int GetAnimeList() { |
175 | 250 if (!account.IsValid()) { |
317
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
251 session.SetStatusBar("AniList: Account isn't valid! (unauthorized?)"); |
175 | 252 return 0; |
253 } | |
254 | |
183
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
175
diff
changeset
|
255 /* NOTE: these really ought to be in the qrc file */ |
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
175
diff
changeset
|
256 constexpr std::string_view query = "query ($id: Int) {\n" |
258 | 257 " MediaListCollection (userId: $id, type: ANIME) {\n" |
258 " lists {\n" | |
259 " name\n" | |
260 " entries {\n" | |
261 " score\n" | |
262 " notes\n" | |
263 " status\n" | |
264 " progress\n" | |
265 " startedAt {\n" | |
266 " year\n" | |
267 " month\n" | |
268 " day\n" | |
269 " }\n" | |
270 " completedAt {\n" | |
271 " year\n" | |
272 " month\n" | |
273 " day\n" | |
274 " }\n" | |
275 " updatedAt\n" | |
276 " media {\n" | |
304
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
277 MEDIA_FIELDS |
258 | 278 " }\n" |
279 " }\n" | |
280 " }\n" | |
281 " }\n" | |
282 "}\n"; | |
9 | 283 // clang-format off |
284 nlohmann::json json = { | |
285 {"query", query}, | |
286 {"variables", { | |
10 | 287 {"id", account.UserId()} |
9 | 288 }} |
289 }; | |
290 // clang-format on | |
175 | 291 |
315
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
292 session.SetStatusBar("AniList: Parsing anime list..."); |
175 | 293 |
315
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
294 nlohmann::json result; |
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
295 const bool res = SendJSONRequest(json, result); |
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
296 if (!res) |
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
297 return 0; |
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
298 |
319
d928ec7b6a0d
services/kitsu: implement GetAnimeList()
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
299 bool success = true; |
d928ec7b6a0d
services/kitsu: implement GetAnimeList()
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
300 |
d928ec7b6a0d
services/kitsu: implement GetAnimeList()
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
301 Anime::db.RemoveAllUserData(); |
d928ec7b6a0d
services/kitsu: implement GetAnimeList()
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
302 |
315
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
303 for (const auto& list : result["data"]["MediaListCollection"]["lists"].items()) |
319
d928ec7b6a0d
services/kitsu: implement GetAnimeList()
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
304 if (!ParseList(list.value())) |
d928ec7b6a0d
services/kitsu: implement GetAnimeList()
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
305 success = false; |
304
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
306 |
319
d928ec7b6a0d
services/kitsu: implement GetAnimeList()
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
307 if (success) |
d928ec7b6a0d
services/kitsu: implement GetAnimeList()
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
308 session.SetStatusBar("AniList: Retrieved anime list successfully!"); |
315
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
309 |
9 | 310 return 1; |
311 } | |
312 | |
250 | 313 /* return is a vector of anime ids */ |
314 std::vector<int> Search(const std::string& search) { | |
258 | 315 constexpr std::string_view query = "query ($search: String) {\n" |
316 " Page (page: 1, perPage: 50) {\n" | |
317 " media (search: $search, type: ANIME) {\n" | |
304
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
318 MEDIA_FIELDS |
258 | 319 " }\n" |
320 " }\n" | |
321 "}\n"; | |
250 | 322 |
323 // clang-format off | |
324 nlohmann::json json = { | |
325 {"query", query}, | |
326 {"variables", { | |
327 {"search", search} | |
328 }} | |
329 }; | |
330 // clang-format on | |
331 | |
315
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
332 nlohmann::json result; |
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
333 const bool res = SendJSONRequest(json, result); |
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
334 if (!res) |
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
335 return {}; |
250 | 336 |
304
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
337 /* FIXME: error handling here */ |
250 | 338 std::vector<int> ret; |
315
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
339 ret.reserve(result["/data/Page/media"_json_pointer].size()); |
250 | 340 |
315
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
341 for (const auto& media : result["/data/Page/media"_json_pointer].items()) |
250 | 342 ret.push_back(ParseMediaJson(media.value())); |
343 | |
344 return ret; | |
345 } | |
346 | |
304
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
347 std::vector<int> GetSeason(Anime::SeriesSeason season, Date::Year year) { |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
348 constexpr std::string_view query = "query ($season: MediaSeason!, $season_year: Int!, $page: Int) {\n" |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
349 " Page(page: $page) {\n" |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
350 " media(season: $season, seasonYear: $season_year, type: ANIME, sort: START_DATE) {\n" |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
351 MEDIA_FIELDS |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
352 " }\n" |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
353 " pageInfo {\n" |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
354 " total\n" |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
355 " perPage\n" |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
356 " currentPage\n" |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
357 " lastPage\n" |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
358 " hasNextPage\n" |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
359 " }\n" |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
360 " }\n" |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
361 "}\n"; |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
362 std::vector<int> ret; |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
363 |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
364 int page = 0; |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
365 bool has_next_page = true; |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
366 while (has_next_page) { |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
367 nlohmann::json json = { |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
368 {"query", query}, |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
369 {"variables", { |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
370 {"season", Translate::AniList::ToString(season)}, |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
371 {"season_year", Strings::ToUtf8String(year)}, |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
372 {"page", page} |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
373 }} |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
374 }; |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
375 |
315
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
376 nlohmann::json result; |
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
377 const bool res = SendJSONRequest(json, result); |
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
378 if (!res) |
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
379 return {}; |
304
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
380 |
315
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
381 ret.reserve(ret.capacity() + result["data"]["Page"]["media"].size()); |
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
382 |
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
383 for (const auto& media : result["data"]["Page"]["media"].items()) |
304
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
384 ret.push_back(ParseMediaJson(media.value())); |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
385 |
315
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
386 has_next_page = JSON::GetBoolean(result, "/data/Page/pageInfo/hasNextPage"_json_pointer, false); |
304
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
387 if (has_next_page) |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
388 page++; |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
389 } |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
390 |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
391 return ret; |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
392 } |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
393 |
52
0c4138de2ea7
anime list: we are finally read-write
Paper <mrpapersonic@gmail.com>
parents:
48
diff
changeset
|
394 int UpdateAnimeEntry(int id) { |
9 | 395 /** |
396 * possible values: | |
15 | 397 * |
9 | 398 * int mediaId, |
399 * MediaListStatus status, | |
400 * float score, | |
401 * int scoreRaw, | |
402 * int progress, | |
184
09492158bcc5
anime: etc. comments and changes
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
403 * int progressVolumes, // manga-specific. |
09492158bcc5
anime: etc. comments and changes
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
404 * int repeat, // rewatch |
258 | 405 * int priority, |
9 | 406 * bool private, |
407 * string notes, | |
408 * bool hiddenFromStatusLists, | |
409 * string[] customLists, | |
410 * float[] advancedScores, | |
411 * Date startedAt, | |
412 * Date completedAt | |
258 | 413 **/ |
52
0c4138de2ea7
anime list: we are finally read-write
Paper <mrpapersonic@gmail.com>
parents:
48
diff
changeset
|
414 Anime::Anime& anime = Anime::db.items[id]; |
184
09492158bcc5
anime: etc. comments and changes
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
415 if (!anime.IsInUserList()) |
09492158bcc5
anime: etc. comments and changes
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
416 return 0; |
09492158bcc5
anime: etc. comments and changes
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
417 |
291 | 418 std::optional<std::string> service_id = anime.GetServiceId(Anime::Service::AniList); |
419 if (!service_id) | |
420 return 0; | |
421 | |
315
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
422 session.SetStatusBar("AniList: Updating anime entry..."); |
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
423 |
250 | 424 constexpr std::string_view query = |
258 | 425 "mutation ($media_id: Int, $progress: Int, $status: MediaListStatus, $score: Int, $notes: String, $start: " |
426 "FuzzyDateInput, $comp: FuzzyDateInput, $repeat: Int) {\n" | |
427 " SaveMediaListEntry (mediaId: $media_id, progress: $progress, status: $status, scoreRaw: $score, notes: " | |
428 "$notes, startedAt: $start, completedAt: $comp, repeat: $repeat) {\n" | |
429 " id\n" | |
430 " }\n" | |
431 "}\n"; | |
9 | 432 // clang-format off |
433 nlohmann::json json = { | |
434 {"query", query}, | |
435 {"variables", { | |
291 | 436 {"media_id", Strings::ToInt<int64_t>(service_id.value())}, |
10 | 437 {"progress", anime.GetUserProgress()}, |
15 | 438 {"status", ListStatusToString(anime)}, |
10 | 439 {"score", anime.GetUserScore()}, |
77 | 440 {"notes", anime.GetUserNotes()}, |
441 {"start", anime.GetUserDateStarted().GetAsAniListJson()}, | |
184
09492158bcc5
anime: etc. comments and changes
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
442 {"comp", anime.GetUserDateCompleted().GetAsAniListJson()}, |
09492158bcc5
anime: etc. comments and changes
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
443 {"repeat", anime.GetUserRewatchedTimes()} |
9 | 444 }} |
445 }; | |
446 // clang-format on | |
175 | 447 |
315
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
448 nlohmann::json result; |
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
449 const bool ret = SendJSONRequest(json, result); |
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
450 if (!ret) |
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
451 return 0; |
175 | 452 |
315
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
453 session.SetStatusBar("AniList: Anime entry updated successfully!"); |
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
454 |
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
455 return JSON::GetNumber(result, "/data/SaveMediaListEntry/id"_json_pointer, 0); |
9 | 456 } |
457 | |
291 | 458 static int ParseUser(const nlohmann::json& json) { |
175 | 459 account.SetUserId(JSON::GetNumber(json, "/id"_json_pointer, 0)); |
10 | 460 return account.UserId(); |
9 | 461 } |
462 | |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
463 bool AuthorizeUser() { |
9 | 464 /* Prompt for PIN */ |
258 | 465 QDesktopServices::openUrl(QUrl(Strings::ToQString("https://anilist.co/api/v2/oauth/authorize?client_id=" + |
291 | 466 std::string(CLIENT_ID) + "&response_type=token"))); |
175 | 467 |
9 | 468 bool ok; |
469 QString token = QInputDialog::getText( | |
258 | 470 0, "Credentials needed!", "Please enter the code given to you after logging in to AniList:", QLineEdit::Normal, |
471 "", &ok); | |
175 | 472 |
473 if (!ok || token.isEmpty()) | |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
474 return false; |
175 | 475 |
476 account.SetAuthToken(Strings::ToUtf8String(token)); | |
477 | |
315
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
478 session.SetStatusBar("AniList: Requesting user ID..."); |
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
479 |
183
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
175
diff
changeset
|
480 constexpr std::string_view query = "query {\n" |
258 | 481 " Viewer {\n" |
482 " id\n" | |
483 " }\n" | |
484 "}\n"; | |
9 | 485 nlohmann::json json = { |
258 | 486 {"query", query} |
487 }; | |
175 | 488 |
315
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
489 /* SendJSONRequest handles status errors */ |
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
490 nlohmann::json result; |
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
491 const bool ret = SendJSONRequest(json, result); |
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
492 if (!ret) |
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
493 return 0; |
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
494 |
319
d928ec7b6a0d
services/kitsu: implement GetAnimeList()
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
495 if (ParseUser(result["data"]["Viewer"])) |
d928ec7b6a0d
services/kitsu: implement GetAnimeList()
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
496 session.SetStatusBar("AniList: Successfully retrieved user data!"); |
d928ec7b6a0d
services/kitsu: implement GetAnimeList()
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
497 else |
d928ec7b6a0d
services/kitsu: implement GetAnimeList()
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
498 session.SetStatusBar("AniList: Failed to retrieve user ID!"); |
d928ec7b6a0d
services/kitsu: implement GetAnimeList()
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
499 |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
500 return true; |
9 | 501 } |
502 | |
63 | 503 } // namespace AniList |
504 } // namespace Services |