Mercurial > minori
diff 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 |
line wrap: on
line diff
--- a/src/services/anilist.cc Wed Jan 24 20:18:59 2024 -0500 +++ b/src/services/anilist.cc Sun Feb 04 21:17:17 2024 -0500 @@ -244,6 +244,59 @@ return 1; } +/* return is a vector of anime ids */ +std::vector<int> Search(const std::string& search) { + constexpr std::string_view query = + "query ($search: String) {\n" + " Page (page: 1, perPage: 50) {\n" + " media (search: $search, type: ANIME) {\n" + " coverImage {\n" + " large\n" + " }\n" + " id\n" + " title {\n" + " romaji\n" + " english\n" + " native\n" + " }\n" + " format\n" + " status\n" + " averageScore\n" + " season\n" + " startDate {\n" + " year\n" + " month\n" + " day\n" + " }\n" + " genres\n" + " episodes\n" + " duration\n" + " synonyms\n" + " description(asHtml: false)\n" + " }\n" + " }\n" + "}\n"; + + // clang-format off + nlohmann::json json = { + {"query", query}, + {"variables", { + {"search", search} + }} + }; + // clang-format on + + auto res = SendJSONRequest(json); + + std::vector<int> ret; + ret.reserve(res["data"]["Page"]["media"].size()); + + for (const auto& media : res["data"]["Page"]["media"].items()) + ret.push_back(ParseMediaJson(media.value())); + + return ret; +} + int UpdateAnimeEntry(int id) { /** * possible values: @@ -263,18 +316,17 @@ * float[] advancedScores, * Date startedAt, * Date completedAt - **/ + **/ Anime::Anime& anime = Anime::db.items[id]; if (!anime.IsInUserList()) return 0; - constexpr std::string_view query = "mutation ($media_id: Int, $progress: Int, $status: MediaListStatus, $score: Int, " - "$notes: String, $start: FuzzyDateInput, $comp: FuzzyDateInput, $repeat: Int) {\n" - " SaveMediaListEntry (mediaId: $media_id, progress: $progress, status: $status, " - "scoreRaw: $score, notes: $notes, startedAt: $start, completedAt: $comp, repeat: $repeat) {\n" - " id\n" - " }\n" - "}\n"; + constexpr std::string_view query = + "mutation ($media_id: Int, $progress: Int, $status: MediaListStatus, $score: Int, $notes: String, $start: FuzzyDateInput, $comp: FuzzyDateInput, $repeat: Int) {\n" + " SaveMediaListEntry (mediaId: $media_id, progress: $progress, status: $status, scoreRaw: $score, notes: $notes, startedAt: $start, completedAt: $comp, repeat: $repeat) {\n" + " id\n" + " }\n" + "}\n"; // clang-format off nlohmann::json json = { {"query", query},