comparison src/services/anilist.cc @ 250:c130f47f6f48

*: many many changes e.g. the search page is actually implemented now!
author Paper <paper@paper.us.eu.org>
date Sun, 04 Feb 2024 21:17:17 -0500
parents d030b30526d5
children 862d0d8619f6
comparison
equal deleted inserted replaced
249:6b2441c776dd 250:c130f47f6f48
242 ParseList(list.value()); 242 ParseList(list.value());
243 } 243 }
244 return 1; 244 return 1;
245 } 245 }
246 246
247 /* return is a vector of anime ids */
248 std::vector<int> Search(const std::string& search) {
249 constexpr std::string_view query =
250 "query ($search: String) {\n"
251 " Page (page: 1, perPage: 50) {\n"
252 " media (search: $search, type: ANIME) {\n"
253 " coverImage {\n"
254 " large\n"
255 " }\n"
256 " id\n"
257 " title {\n"
258 " romaji\n"
259 " english\n"
260 " native\n"
261 " }\n"
262 " format\n"
263 " status\n"
264 " averageScore\n"
265 " season\n"
266 " startDate {\n"
267 " year\n"
268 " month\n"
269 " day\n"
270 " }\n"
271 " genres\n"
272 " episodes\n"
273 " duration\n"
274 " synonyms\n"
275 " description(asHtml: false)\n"
276 " }\n"
277 " }\n"
278 "}\n";
279
280 // clang-format off
281 nlohmann::json json = {
282 {"query", query},
283 {"variables", {
284 {"search", search}
285 }}
286 };
287 // clang-format on
288
289 auto res = SendJSONRequest(json);
290
291 std::vector<int> ret;
292 ret.reserve(res["data"]["Page"]["media"].size());
293
294 for (const auto& media : res["data"]["Page"]["media"].items())
295 ret.push_back(ParseMediaJson(media.value()));
296
297 return ret;
298 }
299
247 int UpdateAnimeEntry(int id) { 300 int UpdateAnimeEntry(int id) {
248 /** 301 /**
249 * possible values: 302 * possible values:
250 * 303 *
251 * int mediaId, 304 * int mediaId,
261 * bool hiddenFromStatusLists, 314 * bool hiddenFromStatusLists,
262 * string[] customLists, 315 * string[] customLists,
263 * float[] advancedScores, 316 * float[] advancedScores,
264 * Date startedAt, 317 * Date startedAt,
265 * Date completedAt 318 * Date completedAt
266 **/ 319 **/
267 Anime::Anime& anime = Anime::db.items[id]; 320 Anime::Anime& anime = Anime::db.items[id];
268 if (!anime.IsInUserList()) 321 if (!anime.IsInUserList())
269 return 0; 322 return 0;
270 323
271 constexpr std::string_view query = "mutation ($media_id: Int, $progress: Int, $status: MediaListStatus, $score: Int, " 324 constexpr std::string_view query =
272 "$notes: String, $start: FuzzyDateInput, $comp: FuzzyDateInput, $repeat: Int) {\n" 325 "mutation ($media_id: Int, $progress: Int, $status: MediaListStatus, $score: Int, $notes: String, $start: FuzzyDateInput, $comp: FuzzyDateInput, $repeat: Int) {\n"
273 " SaveMediaListEntry (mediaId: $media_id, progress: $progress, status: $status, " 326 " SaveMediaListEntry (mediaId: $media_id, progress: $progress, status: $status, scoreRaw: $score, notes: $notes, startedAt: $start, completedAt: $comp, repeat: $repeat) {\n"
274 "scoreRaw: $score, notes: $notes, startedAt: $start, completedAt: $comp, repeat: $repeat) {\n" 327 " id\n"
275 " id\n" 328 " }\n"
276 " }\n" 329 "}\n";
277 "}\n";
278 // clang-format off 330 // clang-format off
279 nlohmann::json json = { 331 nlohmann::json json = {
280 {"query", query}, 332 {"query", query},
281 {"variables", { 333 {"variables", {
282 {"media_id", anime.GetId()}, 334 {"media_id", anime.GetId()},