annotate src/services/anilist.cc @ 291:9a88e1725fd2

*: refactor lots of stuff I forgot to put this into different commits, oops! anyway, it doesn't really matter *that* much since this is an unfinished hobby project anyway. once it starts getting stable commit history will be more important, but for now it's not that big of a deal
author Paper <paper@paper.us.eu.org>
date Sun, 12 May 2024 16:31:07 -0400
parents 53e3c015a973
children 2115488eb302
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
1 #include "services/anilist.h"
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
2 #include "core/anime.h"
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
3 #include "core/anime_db.h"
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
4 #include "core/config.h"
76
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 75
diff changeset
5 #include "core/http.h"
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
6 #include "core/json.h"
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
7 #include "core/session.h"
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
8 #include "core/strings.h"
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
9 #include "gui/translate/anilist.h"
187
9613d72b097e *: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents: 185
diff changeset
10
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
11 #include <QByteArray>
187
9613d72b097e *: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents: 185
diff changeset
12 #include <QDate>
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
13 #include <QDesktopServices>
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
14 #include <QInputDialog>
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
15 #include <QLineEdit>
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
16 #include <QMessageBox>
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
17 #include <QUrl>
187
9613d72b097e *: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents: 185
diff changeset
18
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
19 #include <chrono>
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
20 #include <exception>
291
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 286
diff changeset
21 #include <string_view>
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
22
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
23 #include <iostream>
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
24
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 63
diff changeset
25 using namespace nlohmann::literals::json_literals;
11
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
26
63
3d2decf093bb *: fix many clang warnings
Paper <mrpapersonic@gmail.com>
parents: 52
diff changeset
27 namespace Services {
3d2decf093bb *: fix many clang warnings
Paper <mrpapersonic@gmail.com>
parents: 52
diff changeset
28 namespace AniList {
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
29
291
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 286
diff changeset
30 static constexpr std::string_view CLIENT_ID = "13706";
185
62e336597bb7 anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents: 184
diff changeset
31
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
32 class Account {
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
33 public:
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
34 int UserId() const { return session.config.auth.anilist.user_id; }
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
35 void SetUserId(const int id) { session.config.auth.anilist.user_id = id; }
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
36
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
37 std::string AuthToken() const { return session.config.auth.anilist.auth_token; }
286
53e3c015a973 anime: initial cross-service support
Paper <paper@paper.us.eu.org>
parents: 284
diff changeset
38 void SetAuthToken(const std::string& auth_token) { session.config.auth.anilist.auth_token = auth_token; }
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
39
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
40 bool Authenticated() const { return !AuthToken().empty(); }
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
41 bool IsValid() const { return UserId() && Authenticated(); }
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
42 };
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
43
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
44 static Account account;
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
45
291
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 286
diff changeset
46 static std::string SendRequest(const std::string& data) {
76
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 75
diff changeset
47 std::vector<std::string> headers = {"Authorization: Bearer " + account.AuthToken(), "Accept: application/json",
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
48 "Content-Type: application/json"};
291
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 286
diff changeset
49 return Strings::ToUtf8String(HTTP::Request("https://graphql.anilist.co", headers, data, HTTP::Type::Post));
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
50 }
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
51
291
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 286
diff changeset
52 static nlohmann::json SendJSONRequest(const nlohmann::json& data) {
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
53 std::string request = SendRequest(data.dump());
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
54 if (request.empty()) {
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
55 std::cerr << "[AniList] JSON Request returned an empty result!" << std::endl;
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
56 return {};
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
57 }
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
58
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
59 auto ret = nlohmann::json::parse(request, nullptr, false);
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
60 if (ret.is_discarded()) {
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
61 std::cerr << "[AniList] Failed to parse request JSON!" << std::endl;
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
62 return {};
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
63 }
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
64
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
65 if (ret.contains("/errors"_json_pointer) && ret.at("/errors"_json_pointer).is_array()) {
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
66 for (const auto& error : ret.at("/errors"_json_pointer))
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
67 std::cerr << "[AniList] Received an error in response: "
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
68 << JSON::GetString<std::string>(error, "/message"_json_pointer, "") << std::endl;
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
69
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
70 return {};
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
71 }
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
72
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
73 return ret;
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
74 }
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
75
291
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 286
diff changeset
76 static void ParseListStatus(std::string status, Anime::Anime& anime) {
187
9613d72b097e *: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents: 185
diff changeset
77 static const std::unordered_map<std::string, Anime::ListStatus> map = {
279
657fda1b9cac *: clean up enums
Paper <paper@paper.us.eu.org>
parents: 260
diff changeset
78 {"CURRENT", Anime::ListStatus::Current },
657fda1b9cac *: clean up enums
Paper <paper@paper.us.eu.org>
parents: 260
diff changeset
79 {"PLANNING", Anime::ListStatus::Planning },
657fda1b9cac *: clean up enums
Paper <paper@paper.us.eu.org>
parents: 260
diff changeset
80 {"COMPLETED", Anime::ListStatus::Completed},
657fda1b9cac *: clean up enums
Paper <paper@paper.us.eu.org>
parents: 260
diff changeset
81 {"DROPPED", Anime::ListStatus::Dropped },
657fda1b9cac *: clean up enums
Paper <paper@paper.us.eu.org>
parents: 260
diff changeset
82 {"PAUSED", Anime::ListStatus::Paused }
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
83 };
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
84
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
85 if (status == "REPEATING") {
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
86 anime.SetUserIsRewatching(true);
279
657fda1b9cac *: clean up enums
Paper <paper@paper.us.eu.org>
parents: 260
diff changeset
87 anime.SetUserStatus(Anime::ListStatus::Current);
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
88 return;
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
89 }
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
90
47
d8eb763e6661 information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents: 44
diff changeset
91 if (map.find(status) == map.end()) {
279
657fda1b9cac *: clean up enums
Paper <paper@paper.us.eu.org>
parents: 260
diff changeset
92 anime.SetUserStatus(Anime::ListStatus::NotInList);
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
93 return;
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
94 }
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
95
187
9613d72b097e *: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents: 185
diff changeset
96 anime.SetUserStatus(map.at(status));
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
97 }
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
98
291
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 286
diff changeset
99 static std::string ListStatusToString(const Anime::Anime& anime) {
279
657fda1b9cac *: clean up enums
Paper <paper@paper.us.eu.org>
parents: 260
diff changeset
100 if (anime.GetUserIsRewatching() && anime.GetUserStatus() == Anime::ListStatus::Current)
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
101 return "REWATCHING";
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
102
70
64e5f427c6a2 services/anilist: remove unordered_map usage for enum classes
Paper <mrpapersonic@gmail.com>
parents: 66
diff changeset
103 switch (anime.GetUserStatus()) {
279
657fda1b9cac *: clean up enums
Paper <paper@paper.us.eu.org>
parents: 260
diff changeset
104 case Anime::ListStatus::Planning: return "PLANNING";
657fda1b9cac *: clean up enums
Paper <paper@paper.us.eu.org>
parents: 260
diff changeset
105 case Anime::ListStatus::Completed: return "COMPLETED";
657fda1b9cac *: clean up enums
Paper <paper@paper.us.eu.org>
parents: 260
diff changeset
106 case Anime::ListStatus::Dropped: return "DROPPED";
657fda1b9cac *: clean up enums
Paper <paper@paper.us.eu.org>
parents: 260
diff changeset
107 case Anime::ListStatus::Paused: return "PAUSED";
76
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 75
diff changeset
108 default: break;
70
64e5f427c6a2 services/anilist: remove unordered_map usage for enum classes
Paper <mrpapersonic@gmail.com>
parents: 66
diff changeset
109 }
64e5f427c6a2 services/anilist: remove unordered_map usage for enum classes
Paper <mrpapersonic@gmail.com>
parents: 66
diff changeset
110 return "CURRENT";
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
111 }
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
112
291
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 286
diff changeset
113 static void ParseTitle(const nlohmann::json& json, Anime::Anime& anime) {
284
e66ffc338d82 anime: refactor title structure to a map
Paper <paper@paper.us.eu.org>
parents: 279
diff changeset
114 nlohmann::json::json_pointer g = "/native"_json_pointer;
e66ffc338d82 anime: refactor title structure to a map
Paper <paper@paper.us.eu.org>
parents: 279
diff changeset
115 if (json.contains(g) && json[g].is_string())
e66ffc338d82 anime: refactor title structure to a map
Paper <paper@paper.us.eu.org>
parents: 279
diff changeset
116 anime.SetTitle(Anime::TitleLanguage::Native, json[g]);
e66ffc338d82 anime: refactor title structure to a map
Paper <paper@paper.us.eu.org>
parents: 279
diff changeset
117
e66ffc338d82 anime: refactor title structure to a map
Paper <paper@paper.us.eu.org>
parents: 279
diff changeset
118 g = "/english"_json_pointer;
e66ffc338d82 anime: refactor title structure to a map
Paper <paper@paper.us.eu.org>
parents: 279
diff changeset
119 if (json.contains(g) && json[g].is_string())
e66ffc338d82 anime: refactor title structure to a map
Paper <paper@paper.us.eu.org>
parents: 279
diff changeset
120 anime.SetTitle(Anime::TitleLanguage::English, json[g]);
e66ffc338d82 anime: refactor title structure to a map
Paper <paper@paper.us.eu.org>
parents: 279
diff changeset
121
e66ffc338d82 anime: refactor title structure to a map
Paper <paper@paper.us.eu.org>
parents: 279
diff changeset
122 g = "/romaji"_json_pointer;
e66ffc338d82 anime: refactor title structure to a map
Paper <paper@paper.us.eu.org>
parents: 279
diff changeset
123 if (json.contains(g) && json[g].is_string())
e66ffc338d82 anime: refactor title structure to a map
Paper <paper@paper.us.eu.org>
parents: 279
diff changeset
124 anime.SetTitle(Anime::TitleLanguage::Romaji, json[g]);
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
125 }
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
126
291
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 286
diff changeset
127 static int ParseMediaJson(const nlohmann::json& json) {
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
128 int id = JSON::GetNumber(json, "/id"_json_pointer);
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
129 if (!id)
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
130 return 0;
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
131
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
132 Anime::Anime& anime = Anime::db.items[id];
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
133 anime.SetId(id);
286
53e3c015a973 anime: initial cross-service support
Paper <paper@paper.us.eu.org>
parents: 284
diff changeset
134 anime.SetServiceId(Anime::Service::AniList, Strings::ToUtf8String(id));
53e3c015a973 anime: initial cross-service support
Paper <paper@paper.us.eu.org>
parents: 284
diff changeset
135 anime.SetServiceId(Anime::Service::MyAnimeList, Strings::ToUtf8String(JSON::GetNumber(json, "/id_mal"_json_pointer)));
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
136
11
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
137 ParseTitle(json.at("/title"_json_pointer), anime);
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
138
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
139 anime.SetEpisodes(JSON::GetNumber(json, "/episodes"_json_pointer, 0));
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
140 anime.SetFormat(Translate::AniList::ToSeriesFormat(JSON::GetString<std::string>(json, "/format"_json_pointer, "")));
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
141
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
142 anime.SetAiringStatus(
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
143 Translate::AniList::ToSeriesStatus(JSON::GetString<std::string>(json, "/status"_json_pointer, "")));
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
144
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
145 anime.SetAirDate(Date(json["/startDate"_json_pointer]));
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
146
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
147 anime.SetPosterUrl(JSON::GetString<std::string>(json, "/coverImage/large"_json_pointer, ""));
66
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents: 65
diff changeset
148
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
149 anime.SetAudienceScore(JSON::GetNumber(json, "/averageScore"_json_pointer, 0));
279
657fda1b9cac *: clean up enums
Paper <paper@paper.us.eu.org>
parents: 260
diff changeset
150 // anime.SetSeason(Translate::AniList::ToSeriesSeason(JSON::GetString<std::string>(json, "/season"_json_pointer, "")));
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
151 anime.SetDuration(JSON::GetNumber(json, "/duration"_json_pointer, 0));
260
dd211ff68b36 pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents: 258
diff changeset
152
dd211ff68b36 pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents: 258
diff changeset
153 std::string synopsis = JSON::GetString<std::string>(json, "/description"_json_pointer, "");
dd211ff68b36 pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents: 258
diff changeset
154 Strings::TextifySynopsis(synopsis);
dd211ff68b36 pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents: 258
diff changeset
155 anime.SetSynopsis(synopsis);
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
156
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
157 anime.SetGenres(JSON::GetArray<std::vector<std::string>>(json, "/genres"_json_pointer, {}));
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
158 anime.SetTitleSynonyms(JSON::GetArray<std::vector<std::string>>(json, "/synonyms"_json_pointer, {}));
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
159
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
160 return id;
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
161 }
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
162
291
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 286
diff changeset
163 static int ParseListItem(const nlohmann::json& json) {
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
164 int id = ParseMediaJson(json["media"]);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
165
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
166 Anime::Anime& anime = Anime::db.items[id];
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
167
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
168 anime.AddToUserList();
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
169
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
170 anime.SetUserScore(JSON::GetNumber(json, "/score"_json_pointer, 0));
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
171 anime.SetUserProgress(JSON::GetNumber(json, "/progress"_json_pointer, 0));
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
172 ParseListStatus(JSON::GetString<std::string>(json, "/status"_json_pointer, ""), anime);
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
173 anime.SetUserNotes(JSON::GetString<std::string>(json, "/notes"_json_pointer, ""));
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
174
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
175 anime.SetUserDateStarted(Date(json["/startedAt"_json_pointer]));
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
176 anime.SetUserDateCompleted(Date(json["/completedAt"_json_pointer]));
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
177
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
178 anime.SetUserTimeUpdated(JSON::GetNumber(json, "/updatedAt"_json_pointer, 0));
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
179
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
180 return id;
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
181 }
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
182
291
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 286
diff changeset
183 static int ParseList(const nlohmann::json& json) {
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
184 for (const auto& entry : json["entries"].items()) {
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
185 ParseListItem(entry.value());
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
186 }
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
187 return 1;
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
188 }
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
189
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
190 int GetAnimeList() {
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
191 if (!account.IsValid()) {
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
192 std::cerr << "AniList: Account isn't valid!" << std::endl;
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
193 return 0;
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
194 }
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
195
183
01d259b9c89f pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents: 175
diff changeset
196 /* NOTE: these really ought to be in the qrc file */
01d259b9c89f pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents: 175
diff changeset
197 constexpr std::string_view query = "query ($id: Int) {\n"
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
198 " MediaListCollection (userId: $id, type: ANIME) {\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
199 " lists {\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
200 " name\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
201 " entries {\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
202 " score\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
203 " notes\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
204 " status\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
205 " progress\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
206 " startedAt {\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
207 " year\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
208 " month\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
209 " day\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
210 " }\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
211 " completedAt {\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
212 " year\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
213 " month\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
214 " day\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
215 " }\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
216 " updatedAt\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
217 " media {\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
218 " coverImage {\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
219 " large\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
220 " }\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
221 " id\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
222 " title {\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
223 " romaji\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
224 " english\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
225 " native\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
226 " }\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
227 " format\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
228 " status\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
229 " averageScore\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
230 " season\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
231 " startDate {\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
232 " year\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
233 " month\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
234 " day\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
235 " }\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
236 " genres\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
237 " episodes\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
238 " duration\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
239 " synonyms\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
240 " description(asHtml: false)\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
241 " }\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
242 " }\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
243 " }\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
244 " }\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
245 "}\n";
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
246 // clang-format off
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
247 nlohmann::json json = {
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
248 {"query", query},
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
249 {"variables", {
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
250 {"id", account.UserId()}
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
251 }}
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
252 };
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
253 // clang-format on
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
254
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
255 auto res = SendJSONRequest(json);
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
256
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
257 for (const auto& list : res["data"]["MediaListCollection"]["lists"].items()) {
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
258 ParseList(list.value());
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
259 }
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
260 return 1;
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
261 }
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
262
250
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 228
diff changeset
263 /* return is a vector of anime ids */
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 228
diff changeset
264 std::vector<int> Search(const std::string& search) {
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
265 constexpr std::string_view query = "query ($search: String) {\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
266 " Page (page: 1, perPage: 50) {\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
267 " media (search: $search, type: ANIME) {\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
268 " coverImage {\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
269 " large\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
270 " }\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
271 " id\n"
286
53e3c015a973 anime: initial cross-service support
Paper <paper@paper.us.eu.org>
parents: 284
diff changeset
272 " id_mal\n"
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
273 " title {\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
274 " romaji\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
275 " english\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
276 " native\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
277 " }\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
278 " format\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
279 " status\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
280 " averageScore\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
281 " season\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
282 " startDate {\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
283 " year\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
284 " month\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
285 " day\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
286 " }\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
287 " genres\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
288 " episodes\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
289 " duration\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
290 " synonyms\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
291 " description(asHtml: false)\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
292 " }\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
293 " }\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
294 "}\n";
250
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 228
diff changeset
295
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 228
diff changeset
296 // clang-format off
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 228
diff changeset
297 nlohmann::json json = {
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 228
diff changeset
298 {"query", query},
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 228
diff changeset
299 {"variables", {
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 228
diff changeset
300 {"search", search}
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 228
diff changeset
301 }}
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 228
diff changeset
302 };
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 228
diff changeset
303 // clang-format on
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 228
diff changeset
304
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 228
diff changeset
305 auto res = SendJSONRequest(json);
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 228
diff changeset
306
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 228
diff changeset
307 std::vector<int> ret;
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 228
diff changeset
308 ret.reserve(res["data"]["Page"]["media"].size());
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 228
diff changeset
309
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 228
diff changeset
310 for (const auto& media : res["data"]["Page"]["media"].items())
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 228
diff changeset
311 ret.push_back(ParseMediaJson(media.value()));
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 228
diff changeset
312
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 228
diff changeset
313 return ret;
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 228
diff changeset
314 }
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 228
diff changeset
315
52
0c4138de2ea7 anime list: we are finally read-write
Paper <mrpapersonic@gmail.com>
parents: 48
diff changeset
316 int UpdateAnimeEntry(int id) {
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
317 /**
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
318 * possible values:
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
319 *
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
320 * int mediaId,
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
321 * MediaListStatus status,
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
322 * float score,
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
323 * int scoreRaw,
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
324 * int progress,
184
09492158bcc5 anime: etc. comments and changes
Paper <mrpapersonic@gmail.com>
parents: 183
diff changeset
325 * int progressVolumes, // manga-specific.
09492158bcc5 anime: etc. comments and changes
Paper <mrpapersonic@gmail.com>
parents: 183
diff changeset
326 * int repeat, // rewatch
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
327 * int priority,
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
328 * bool private,
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
329 * string notes,
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
330 * bool hiddenFromStatusLists,
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
331 * string[] customLists,
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
332 * float[] advancedScores,
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
333 * Date startedAt,
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
334 * Date completedAt
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
335 **/
52
0c4138de2ea7 anime list: we are finally read-write
Paper <mrpapersonic@gmail.com>
parents: 48
diff changeset
336 Anime::Anime& anime = Anime::db.items[id];
184
09492158bcc5 anime: etc. comments and changes
Paper <mrpapersonic@gmail.com>
parents: 183
diff changeset
337 if (!anime.IsInUserList())
09492158bcc5 anime: etc. comments and changes
Paper <mrpapersonic@gmail.com>
parents: 183
diff changeset
338 return 0;
09492158bcc5 anime: etc. comments and changes
Paper <mrpapersonic@gmail.com>
parents: 183
diff changeset
339
291
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 286
diff changeset
340 std::optional<std::string> service_id = anime.GetServiceId(Anime::Service::AniList);
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 286
diff changeset
341 if (!service_id)
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 286
diff changeset
342 return 0;
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 286
diff changeset
343
250
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 228
diff changeset
344 constexpr std::string_view query =
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
345 "mutation ($media_id: Int, $progress: Int, $status: MediaListStatus, $score: Int, $notes: String, $start: "
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
346 "FuzzyDateInput, $comp: FuzzyDateInput, $repeat: Int) {\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
347 " SaveMediaListEntry (mediaId: $media_id, progress: $progress, status: $status, scoreRaw: $score, notes: "
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
348 "$notes, startedAt: $start, completedAt: $comp, repeat: $repeat) {\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
349 " id\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
350 " }\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
351 "}\n";
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
352 // clang-format off
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
353 nlohmann::json json = {
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
354 {"query", query},
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
355 {"variables", {
291
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 286
diff changeset
356 {"media_id", Strings::ToInt<int64_t>(service_id.value())},
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
357 {"progress", anime.GetUserProgress()},
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
358 {"status", ListStatusToString(anime)},
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
359 {"score", anime.GetUserScore()},
77
6f7385bd334c *: update
Paper <mrpapersonic@gmail.com>
parents: 76
diff changeset
360 {"notes", anime.GetUserNotes()},
6f7385bd334c *: update
Paper <mrpapersonic@gmail.com>
parents: 76
diff changeset
361 {"start", anime.GetUserDateStarted().GetAsAniListJson()},
184
09492158bcc5 anime: etc. comments and changes
Paper <mrpapersonic@gmail.com>
parents: 183
diff changeset
362 {"comp", anime.GetUserDateCompleted().GetAsAniListJson()},
09492158bcc5 anime: etc. comments and changes
Paper <mrpapersonic@gmail.com>
parents: 183
diff changeset
363 {"repeat", anime.GetUserRewatchedTimes()}
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
364 }}
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
365 };
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
366 // clang-format on
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
367
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
368 auto ret = SendJSONRequest(json);
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
369
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
370 return JSON::GetNumber(ret, "/data/SaveMediaListEntry/id"_json_pointer, 0);
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
371 }
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
372
291
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 286
diff changeset
373 static int ParseUser(const nlohmann::json& json) {
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
374 account.SetUserId(JSON::GetNumber(json, "/id"_json_pointer, 0));
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
375 return account.UserId();
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
376 }
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
377
44
619cbd6e69f9 filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents: 36
diff changeset
378 bool AuthorizeUser() {
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
379 /* Prompt for PIN */
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
380 QDesktopServices::openUrl(QUrl(Strings::ToQString("https://anilist.co/api/v2/oauth/authorize?client_id=" +
291
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 286
diff changeset
381 std::string(CLIENT_ID) + "&response_type=token")));
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
382
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
383 bool ok;
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
384 QString token = QInputDialog::getText(
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
385 0, "Credentials needed!", "Please enter the code given to you after logging in to AniList:", QLineEdit::Normal,
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
386 "", &ok);
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
387
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
388 if (!ok || token.isEmpty())
44
619cbd6e69f9 filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents: 36
diff changeset
389 return false;
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
390
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
391 account.SetAuthToken(Strings::ToUtf8String(token));
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
392
183
01d259b9c89f pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents: 175
diff changeset
393 constexpr std::string_view query = "query {\n"
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
394 " Viewer {\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
395 " id\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
396 " name\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
397 " mediaListOptions {\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
398 " scoreFormat\n" // this will be used... eventually
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
399 " }\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
400 " }\n"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
401 "}\n";
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
402 nlohmann::json json = {
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
403 {"query", query}
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 250
diff changeset
404 };
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
405
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
406 auto ret = SendJSONRequest(json);
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
407
74
5ccb99bfa605 fix regressions on macOS
Paper <mrpapersonic@gmail.com>
parents: 70
diff changeset
408 ParseUser(ret["data"]["Viewer"]);
44
619cbd6e69f9 filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents: 36
diff changeset
409 return true;
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
410 }
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
411
63
3d2decf093bb *: fix many clang warnings
Paper <mrpapersonic@gmail.com>
parents: 52
diff changeset
412 } // namespace AniList
3d2decf093bb *: fix many clang warnings
Paper <mrpapersonic@gmail.com>
parents: 52
diff changeset
413 } // namespace Services