diff 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
line wrap: on
line diff
--- a/src/anilist.cpp	Wed Aug 16 00:49:17 2023 -0400
+++ b/src/anilist.cpp	Thu Aug 24 23:11:38 2023 -0400
@@ -1,15 +1,22 @@
-#include "window.h"
-#include "json.h"
+#include <QMessageBox>
+#include <QDesktopServices>
+#include <QInputDialog>
+#include <QLineEdit>
 #include <curl/curl.h>
 #include <chrono>
 #include <exception>
 #include <format>
+#include "json.h"
 #include "anilist.h"
 #include "anime.h"
 #include "config.h"
 #include "string_utils.h"
+#include "session.h"
 #define CLIENT_ID "13706"
 
+CURL* AniList::curl = NULL;
+CURLcode AniList::res = (CURLcode)0;
+
 size_t AniList::CurlWriteCallback(void *contents, size_t size, size_t nmemb, void *userdata) {
     ((std::string*)userdata)->append((char*)contents, size * nmemb);
     return size * nmemb;
@@ -190,10 +197,6 @@
 			anime.title.native  = JSON::GetString(entry.value(), "/media/title/native"_json_pointer);
 			anime.title.english = JSON::GetString(entry.value(), "/media/title/english"_json_pointer);
 			anime.title.romaji  = JSON::GetString(entry.value(), "/media/title/romaji"_json_pointer);
-			/* fallback to romaji if english is not available
-			   note that this takes up more space in memory and is stinky */
-			if (anime.title.english.empty())
-				anime.title.english = anime.title.romaji;
 
 			anime.id = JSON::GetInt(entry.value(), "/media/id"_json_pointer);
 			anime.episodes = JSON::GetInt(entry.value(), "/media/episodes"_json_pointer);
@@ -210,8 +213,10 @@
 			anime.duration = JSON::GetInt(entry.value(), "/media/duration"_json_pointer);
 			anime.synopsis = StringUtils::TextifySynopsis(JSON::GetString(entry.value(), "/media/description"_json_pointer));
 
-			if (entry.value()["media"]["genres"].is_array())
-				anime.genres = entry.value()["media"]["genres"].get<std::vector<std::string>>();
+			if (entry.value().contains("/media/genres"_json_pointer) && entry.value()["/media/genres"_json_pointer].is_array())
+				anime.genres = entry.value()["/media/genres"_json_pointer].get<std::vector<std::string>>();
+			if (entry.value().contains("/media/synonyms"_json_pointer) && entry.value()["/media/synonyms"_json_pointer].is_array())
+				anime.synonyms = entry.value()["/media/synonyms"_json_pointer].get<std::vector<std::string>>();
 			anime_list.Add(anime);
 		}
 		anime_lists->push_back(anime_list);