Mercurial > minori
comparison src/anilist.cpp @ 2:23d0d9319a00
Update
Also converted everything to LF from CRLF
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Sat, 12 Aug 2023 03:16:26 -0400 |
| parents | 1ae666fdf9e2 |
| children | 190ded9438c0 |
comparison
equal
deleted
inserted
replaced
| 1:1ae666fdf9e2 | 2:23d0d9319a00 |
|---|---|
| 107 {"NOVEL", NOVEL}, | 107 {"NOVEL", NOVEL}, |
| 108 {"ONE_SHOT", ONE_SHOT} | 108 {"ONE_SHOT", ONE_SHOT} |
| 109 }; | 109 }; |
| 110 | 110 |
| 111 int AniList::UpdateAnimeList(std::vector<AnimeList>* anime_lists, int id) { | 111 int AniList::UpdateAnimeList(std::vector<AnimeList>* anime_lists, int id) { |
| 112 /* NOTE: these should be in the qrc file */ | |
| 112 #define QUERY "query ($id: Int) {\n" \ | 113 #define QUERY "query ($id: Int) {\n" \ |
| 113 " MediaListCollection (userId: $id, type: ANIME) {\n" \ | 114 " MediaListCollection (userId: $id, type: ANIME) {\n" \ |
| 114 " lists {\n" \ | 115 " lists {\n" \ |
| 115 " name\n" \ | 116 " name\n" \ |
| 116 " entries {\n" \ | 117 " entries {\n" \ |
| 125 " completedAt {\n" \ | 126 " completedAt {\n" \ |
| 126 " year\n" \ | 127 " year\n" \ |
| 127 " month\n" \ | 128 " month\n" \ |
| 128 " day\n" \ | 129 " day\n" \ |
| 129 " }\n" \ | 130 " }\n" \ |
| 131 " updatedAt\n" \ | |
| 130 " media {\n" \ | 132 " media {\n" \ |
| 131 " id\n" \ | 133 " id\n" \ |
| 132 " title {\n" \ | 134 " title {\n" \ |
| 133 " userPreferred\n" \ | 135 " romaji\n" \ |
| 136 " english\n" \ | |
| 137 " native\n" \ | |
| 134 " }\n" \ | 138 " }\n" \ |
| 135 " format\n" \ | 139 " format\n" \ |
| 136 " status\n" \ | 140 " status\n" \ |
| 137 " averageScore\n" \ | 141 " averageScore\n" \ |
| 138 " season\n" \ | 142 " season\n" \ |
| 164 if we can just get wide strings back from nlohmann::json */ | 168 if we can just get wide strings back from nlohmann::json */ |
| 165 for (const auto& list : res["data"]["MediaListCollection"]["lists"].items()) { | 169 for (const auto& list : res["data"]["MediaListCollection"]["lists"].items()) { |
| 166 /* why are the .key() values strings?? */ | 170 /* why are the .key() values strings?? */ |
| 167 int list_key = std::stoi(list.key()); | 171 int list_key = std::stoi(list.key()); |
| 168 AnimeList anime_list; | 172 AnimeList anime_list; |
| 169 anime_list.name = StringUtils::Utf8ToWstr(list.value()["name"].get<std::string>()); | 173 anime_list.name = StringUtils::Utf8ToWstr(JSON::GetString(list.value(), "name")); |
| 170 for (const auto& entry : list.value()["entries"].items()) { | 174 for (const auto& entry : list.value()["entries"].items()) { |
| 171 int entry_key = std::stoi(entry.key()); | 175 int entry_key = std::stoi(entry.key()); |
| 172 Anime anime; | 176 Anime anime; |
| 173 anime.score = entry.value()["score"].get<int>(); | 177 anime.score = JSON::GetInt(entry.value(), "score"); |
| 174 anime.progress = entry.value()["progress"].get<int>(); | 178 anime.progress = JSON::GetInt(entry.value(), "progress"); |
| 175 if (entry.value()["status"].is_string()) | 179 anime.status = StringToAnimeWatchingMap[JSON::GetString(entry.value(), "status")]; |
| 176 anime.status = StringToAnimeWatchingMap[entry.value()["status"].get<std::string>()]; | 180 anime.notes = StringUtils::Utf8ToWstr(JSON::GetString(entry.value(), "notes")); |
| 177 if (entry.value()["notes"].is_string()) | 181 |
| 178 anime.notes = StringUtils::Utf8ToWstr(entry.value()["notes"].get<std::string>()); | 182 anime.started.SetYear(JSON::GetInt(entry.value()["startedAt"], "year")); |
| 179 | 183 anime.started.SetMonth(JSON::GetInt(entry.value()["startedAt"], "month")); |
| 180 if (ANILIST_DATE_IS_VALID(entry.value()["startedAt"])) | 184 anime.started.SetDay(JSON::GetInt(entry.value()["startedAt"], "day")); |
| 181 anime.started = ANILIST_DATE_TO_YMD(entry.value()["startedAt"]); | 185 |
| 182 if (ANILIST_DATE_IS_VALID(entry.value()["completedAt"])) | 186 anime.completed.SetYear(JSON::GetInt(entry.value()["completedAt"], "year")); |
| 183 anime.completed = ANILIST_DATE_TO_YMD(entry.value()["completedAt"]); | 187 anime.completed.SetMonth(JSON::GetInt(entry.value()["completedAt"], "month")); |
| 184 | 188 anime.completed.SetDay(JSON::GetInt(entry.value()["completedAt"], "day")); |
| 185 anime.title = StringUtils::Utf8ToWstr(entry.value()["media"]["title"]["userPreferred"].get<std::string>()); | 189 |
| 186 anime.id = entry.value()["media"]["id"].get<int>(); | 190 anime.updated = JSON::GetInt(entry.value(), "updatedAt"); |
| 187 if (!entry.value()["media"]["episodes"].is_null()) | 191 |
| 188 anime.episodes = entry.value()["media"]["episodes"].get<int>(); | 192 anime.title.native = StringUtils::Utf8ToWstr(JSON::GetString(entry.value()["media"]["title"], "native")); |
| 189 else // hasn't aired yet | 193 anime.title.english = StringUtils::Utf8ToWstr(JSON::GetString(entry.value()["media"]["title"], "english")); |
| 190 anime.episodes = 0; | 194 anime.title.romaji = StringUtils::Utf8ToWstr(JSON::GetString(entry.value()["media"]["title"], "romaji")); |
| 191 | 195 |
| 192 if (!entry.value()["media"]["format"].is_null()) | 196 anime.id = JSON::GetInt(entry.value()["media"], "id"); |
| 193 anime.type = StringToAnimeFormatMap[entry.value()["media"]["format"].get<std::string>()]; | 197 anime.episodes = JSON::GetInt(entry.value()["media"], "episodes"); |
| 194 | 198 anime.type = StringToAnimeFormatMap[JSON::GetString(entry.value()["media"], "format")]; |
| 195 anime.airing = StringToAnimeAiringMap[entry.value()["media"]["status"].get<std::string>()]; | 199 |
| 196 | 200 anime.airing = StringToAnimeAiringMap[JSON::GetString(entry.value()["media"], "status")]; |
| 197 if (ANILIST_DATE_IS_VALID(entry.value()["media"]["startDate"])) | 201 |
| 198 anime.air_date = ANILIST_DATE_TO_YMD(entry.value()["media"]["startDate"]); | 202 anime.air_date.SetYear(JSON::GetInt(entry.value()["media"]["startDate"], "year")); |
| 199 | 203 anime.air_date.SetMonth(JSON::GetInt(entry.value()["media"]["startDate"], "month")); |
| 200 if (entry.value()["media"]["averageScore"].is_number()) | 204 anime.air_date.SetDay(JSON::GetInt(entry.value()["media"]["startDate"], "day")); |
| 201 anime.audience_score = entry.value()["media"]["averageScore"].get<int>(); | 205 |
| 202 | 206 anime.audience_score = JSON::GetInt(entry.value()["media"], "averageScore"); |
| 203 if (entry.value()["media"]["season"].is_string()) | 207 anime.season = StringToAnimeSeasonMap[JSON::GetString(entry.value()["media"], "season")]; |
| 204 anime.season = StringToAnimeSeasonMap[entry.value()["media"]["season"].get<std::string>()]; | 208 anime.duration = JSON::GetInt(entry.value()["media"], "duration"); |
| 205 | 209 anime.synopsis = StringUtils::TextifySynopsis(StringUtils::Utf8ToWstr(JSON::GetString(entry.value()["media"], "duration"))); |
| 206 if (entry.value()["media"]["duration"].is_number()) | |
| 207 anime.duration = entry.value()["media"]["duration"].get<int>(); | |
| 208 else | |
| 209 anime.duration = 0; | |
| 210 | 210 |
| 211 if (entry.value()["media"]["genres"].is_array()) | 211 if (entry.value()["media"]["genres"].is_array()) |
| 212 anime.genres = entry.value()["media"]["genres"].get<std::vector<std::string>>(); | 212 anime.genres = entry.value()["media"]["genres"].get<std::vector<std::string>>(); |
| 213 if (entry.value()["media"]["description"].is_string()) | |
| 214 anime.synopsis = StringUtils::TextifySynopsis(StringUtils::Utf8ToWstr(entry.value()["media"]["description"].get<std::string>())); | |
| 215 anime_list.Add(anime); | 213 anime_list.Add(anime); |
| 216 } | 214 } |
| 217 anime_lists->push_back(anime_list); | 215 anime_lists->push_back(anime_list); |
| 218 } | 216 } |
| 219 return 1; | 217 return 1; |
| 218 #undef QUERY | |
| 220 } | 219 } |
| 221 | 220 |
| 222 int AniList::Authorize() { | 221 int AniList::Authorize() { |
| 223 if (session.config.anilist.auth_token.empty()) { | 222 if (session.config.anilist.auth_token.empty()) { |
| 224 /* Prompt for PIN */ | 223 /* Prompt for PIN */ |
