comparison src/services/anilist.cpp @ 11:fc1bf97c528b

*: use C++11 standard I've been meaning to do this for a while, but I didn't want to reimplement the filesystem code. Now we are on C++11 and most compilers from the past 5 centuries should support this now
author Paper <mrpapersonic@gmail.com>
date Sun, 17 Sep 2023 06:14:30 -0400
parents 4b198a111713
children cde8f67a7c7d
comparison
equal deleted inserted replaced
10:4b198a111713 11:fc1bf97c528b
13 #include <chrono> 13 #include <chrono>
14 #include <curl/curl.h> 14 #include <curl/curl.h>
15 #include <exception> 15 #include <exception>
16 #include <format> 16 #include <format>
17 #define CLIENT_ID "13706" 17 #define CLIENT_ID "13706"
18
19 using nlohmann::literals::operator "" _json_pointer;
18 20
19 namespace Services::AniList { 21 namespace Services::AniList {
20 22
21 class Account { 23 class Account {
22 public: 24 public:
117 {"ONE_SHOT", Anime::SeriesFormat::ONE_SHOT} 119 {"ONE_SHOT", Anime::SeriesFormat::ONE_SHOT}
118 }; 120 };
119 121
120 Date ParseDate(const nlohmann::json& json) { 122 Date ParseDate(const nlohmann::json& json) {
121 Date date; 123 Date date;
122 if (json.contains("/year"_json_pointer) && json["/year"_json_pointer].is_number()) 124 if (json.contains("/year"_json_pointer) && json.at("/year"_json_pointer).is_number())
123 date.SetYear(JSON::GetInt(json, "/year"_json_pointer)); 125 date.SetYear(JSON::GetInt(json, "/year"_json_pointer));
124 else 126 else
125 date.VoidYear(); 127 date.VoidYear();
126 128
127 if (json.contains("/month"_json_pointer) && json["/month"_json_pointer].is_number()) 129 if (json.contains("/month"_json_pointer) && json.at("/month"_json_pointer).is_number())
128 date.SetMonth(JSON::GetInt(json, "/month"_json_pointer)); 130 date.SetMonth(JSON::GetInt(json, "/month"_json_pointer));
129 else 131 else
130 date.VoidMonth(); 132 date.VoidMonth();
131 133
132 if (json.contains("/day"_json_pointer) && json["/day"_json_pointer].is_number()) 134 if (json.contains("/day"_json_pointer) && json.at("/day"_json_pointer).is_number())
133 date.SetDay(JSON::GetInt(json, "/day"_json_pointer)); 135 date.SetDay(JSON::GetInt(json, "/day"_json_pointer));
134 else 136 else
135 date.VoidDay(); 137 date.VoidDay();
136 return date; 138 return date;
137 } 139 }
147 if (!id) 149 if (!id)
148 return 0; 150 return 0;
149 Anime::Anime& anime = Anime::db.items[id]; 151 Anime::Anime& anime = Anime::db.items[id];
150 anime.SetId(id); 152 anime.SetId(id);
151 153
152 ParseTitle(json["/title"_json_pointer], anime); 154 ParseTitle(json.at("/title"_json_pointer), anime);
153 155
154 anime.SetEpisodes(JSON::GetInt(json, "/episodes"_json_pointer)); 156 anime.SetEpisodes(JSON::GetInt(json, "/episodes"_json_pointer));
155 anime.SetFormat(AniListStringToAnimeFormatMap[JSON::GetString(json, "/format"_json_pointer)]); 157 anime.SetFormat(AniListStringToAnimeFormatMap[JSON::GetString(json, "/format"_json_pointer)]);
156 158
157 anime.SetAiringStatus(AniListStringToAnimeAiringMap[JSON::GetString(json, "/status"_json_pointer)]); 159 anime.SetAiringStatus(AniListStringToAnimeAiringMap[JSON::GetString(json, "/status"_json_pointer)]);