Mercurial > minori
comparison src/services/anilist.cpp @ 64:fe719c109dbc
*: update
1. add media tracking ability, and it displays info on the `now playing` page
2. the `now playing` page now actually shows something
3. renamed every page class to be more accurate to what it is
4. ...
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sun, 01 Oct 2023 23:15:43 -0400 |
parents | 3d2decf093bb |
children | 26721c28bf22 |
comparison
equal
deleted
inserted
replaced
63:3d2decf093bb | 64:fe719c109dbc |
---|---|
4 #include "core/config.h" | 4 #include "core/config.h" |
5 #include "core/json.h" | 5 #include "core/json.h" |
6 #include "core/session.h" | 6 #include "core/session.h" |
7 #include "core/strings.h" | 7 #include "core/strings.h" |
8 #include "gui/translate/anilist.h" | 8 #include "gui/translate/anilist.h" |
9 #include <QDebug> | |
10 #include <QDesktopServices> | 9 #include <QDesktopServices> |
11 #include <QInputDialog> | 10 #include <QInputDialog> |
12 #include <QLineEdit> | 11 #include <QLineEdit> |
13 #include <QMessageBox> | 12 #include <QMessageBox> |
14 #include <QUrl> | 13 #include <QUrl> |
15 #include <chrono> | 14 #include <chrono> |
16 #include <curl/curl.h> | 15 #include <curl/curl.h> |
17 #include <exception> | 16 #include <exception> |
18 #define CLIENT_ID "13706" | 17 #define CLIENT_ID "13706" |
19 | 18 |
20 using nlohmann::literals::operator"" _json_pointer; | 19 using namespace nlohmann::literals::json_literals; |
21 | 20 |
22 namespace Services { | 21 namespace Services { |
23 namespace AniList { | 22 namespace AniList { |
24 | 23 |
25 class Account { | 24 class Account { |
37 }; | 36 }; |
38 | 37 |
39 static Account account; | 38 static Account account; |
40 | 39 |
41 static size_t CurlWriteCallback(void* contents, size_t size, size_t nmemb, void* userdata) { | 40 static size_t CurlWriteCallback(void* contents, size_t size, size_t nmemb, void* userdata) { |
42 ((std::string*)userdata)->append((char*)contents, size * nmemb); | 41 reinterpret_cast<std::string*>(userdata)->append(reinterpret_cast<char*>(contents), size * nmemb); |
43 return size * nmemb; | 42 return size * nmemb; |
44 } | 43 } |
45 | 44 |
46 /* A wrapper around cURL to send requests to AniList */ | 45 /* A wrapper around cURL to send requests to AniList */ |
47 std::string SendRequest(std::string data) { | 46 std::string SendRequest(std::string data) { |
115 return map[anime.GetUserStatus()]; | 114 return map[anime.GetUserStatus()]; |
116 } | 115 } |
117 | 116 |
118 Date ParseDate(const nlohmann::json& json) { | 117 Date ParseDate(const nlohmann::json& json) { |
119 Date date; | 118 Date date; |
119 /* JSON for Modern C++ warns here. I'm not too sure why, this code works when I set the | |
120 standard to C++17 :/ */ | |
120 if (json.contains("/year"_json_pointer) && json.at("/year"_json_pointer).is_number()) | 121 if (json.contains("/year"_json_pointer) && json.at("/year"_json_pointer).is_number()) |
121 date.SetYear(JSON::GetInt(json, "/year"_json_pointer)); | 122 date.SetYear(JSON::GetInt(json, "/year"_json_pointer)); |
122 else | 123 else |
123 date.VoidYear(); | 124 date.VoidYear(); |
124 | 125 |