comparison src/anilist.cpp @ 7:07a9095eaeed

Update Refactored some code, moved some around
author Paper <mrpapersonic@gmail.com>
date Thu, 24 Aug 2023 23:11:38 -0400
parents 1d82f6e04d7d
children
comparison
equal deleted inserted replaced
6:1d82f6e04d7d 7:07a9095eaeed
1 #include "window.h" 1 #include <QMessageBox>
2 #include "json.h" 2 #include <QDesktopServices>
3 #include <QInputDialog>
4 #include <QLineEdit>
3 #include <curl/curl.h> 5 #include <curl/curl.h>
4 #include <chrono> 6 #include <chrono>
5 #include <exception> 7 #include <exception>
6 #include <format> 8 #include <format>
9 #include "json.h"
7 #include "anilist.h" 10 #include "anilist.h"
8 #include "anime.h" 11 #include "anime.h"
9 #include "config.h" 12 #include "config.h"
10 #include "string_utils.h" 13 #include "string_utils.h"
14 #include "session.h"
11 #define CLIENT_ID "13706" 15 #define CLIENT_ID "13706"
16
17 CURL* AniList::curl = NULL;
18 CURLcode AniList::res = (CURLcode)0;
12 19
13 size_t AniList::CurlWriteCallback(void *contents, size_t size, size_t nmemb, void *userdata) { 20 size_t AniList::CurlWriteCallback(void *contents, size_t size, size_t nmemb, void *userdata) {
14 ((std::string*)userdata)->append((char*)contents, size * nmemb); 21 ((std::string*)userdata)->append((char*)contents, size * nmemb);
15 return size * nmemb; 22 return size * nmemb;
16 } 23 }
188 anime.updated = JSON::GetInt(entry.value(), "/updatedAt"_json_pointer); 195 anime.updated = JSON::GetInt(entry.value(), "/updatedAt"_json_pointer);
189 196
190 anime.title.native = JSON::GetString(entry.value(), "/media/title/native"_json_pointer); 197 anime.title.native = JSON::GetString(entry.value(), "/media/title/native"_json_pointer);
191 anime.title.english = JSON::GetString(entry.value(), "/media/title/english"_json_pointer); 198 anime.title.english = JSON::GetString(entry.value(), "/media/title/english"_json_pointer);
192 anime.title.romaji = JSON::GetString(entry.value(), "/media/title/romaji"_json_pointer); 199 anime.title.romaji = JSON::GetString(entry.value(), "/media/title/romaji"_json_pointer);
193 /* fallback to romaji if english is not available
194 note that this takes up more space in memory and is stinky */
195 if (anime.title.english.empty())
196 anime.title.english = anime.title.romaji;
197 200
198 anime.id = JSON::GetInt(entry.value(), "/media/id"_json_pointer); 201 anime.id = JSON::GetInt(entry.value(), "/media/id"_json_pointer);
199 anime.episodes = JSON::GetInt(entry.value(), "/media/episodes"_json_pointer); 202 anime.episodes = JSON::GetInt(entry.value(), "/media/episodes"_json_pointer);
200 anime.type = StringToAnimeFormatMap[JSON::GetString(entry.value()["media"], "/media/format"_json_pointer)]; 203 anime.type = StringToAnimeFormatMap[JSON::GetString(entry.value()["media"], "/media/format"_json_pointer)];
201 204
208 anime.audience_score = JSON::GetInt(entry.value(), "/media/averageScore"_json_pointer); 211 anime.audience_score = JSON::GetInt(entry.value(), "/media/averageScore"_json_pointer);
209 anime.season = StringToAnimeSeasonMap[JSON::GetString(entry.value(), "/media/season"_json_pointer)]; 212 anime.season = StringToAnimeSeasonMap[JSON::GetString(entry.value(), "/media/season"_json_pointer)];
210 anime.duration = JSON::GetInt(entry.value(), "/media/duration"_json_pointer); 213 anime.duration = JSON::GetInt(entry.value(), "/media/duration"_json_pointer);
211 anime.synopsis = StringUtils::TextifySynopsis(JSON::GetString(entry.value(), "/media/description"_json_pointer)); 214 anime.synopsis = StringUtils::TextifySynopsis(JSON::GetString(entry.value(), "/media/description"_json_pointer));
212 215
213 if (entry.value()["media"]["genres"].is_array()) 216 if (entry.value().contains("/media/genres"_json_pointer) && entry.value()["/media/genres"_json_pointer].is_array())
214 anime.genres = entry.value()["media"]["genres"].get<std::vector<std::string>>(); 217 anime.genres = entry.value()["/media/genres"_json_pointer].get<std::vector<std::string>>();
218 if (entry.value().contains("/media/synonyms"_json_pointer) && entry.value()["/media/synonyms"_json_pointer].is_array())
219 anime.synonyms = entry.value()["/media/synonyms"_json_pointer].get<std::vector<std::string>>();
215 anime_list.Add(anime); 220 anime_list.Add(anime);
216 } 221 }
217 anime_lists->push_back(anime_list); 222 anime_lists->push_back(anime_list);
218 } 223 }
219 return 1; 224 return 1;