annotate src/services/anilist.cc @ 184:09492158bcc5

anime: etc. comments and changes
author Paper <mrpapersonic@gmail.com>
date Mon, 04 Dec 2023 13:44:42 -0500
parents 01d259b9c89f
children 62e336597bb7
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"
77
6f7385bd334c *: update
Paper <mrpapersonic@gmail.com>
parents: 76
diff changeset
10 #include <QByteArray>
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
11 #include <QDesktopServices>
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
12 #include <QInputDialog>
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
13 #include <QLineEdit>
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
14 #include <QMessageBox>
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
15 #include <QUrl>
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
16 #include <chrono>
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
17 #include <exception>
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
18
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
19 #include <iostream>
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
20
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
21 #define CLIENT_ID "13706"
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
22
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 63
diff changeset
23 using namespace nlohmann::literals::json_literals;
11
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
24
63
3d2decf093bb *: fix many clang warnings
Paper <mrpapersonic@gmail.com>
parents: 52
diff changeset
25 namespace Services {
3d2decf093bb *: fix many clang warnings
Paper <mrpapersonic@gmail.com>
parents: 52
diff changeset
26 namespace AniList {
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
27
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
28 class Account {
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
29 public:
120
275da698697d config: template-ify INI
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
30 std::string Username() const { return session.config.auth.anilist.username; }
275da698697d config: template-ify INI
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
31 void SetUsername(std::string const& username) { session.config.auth.anilist.username = username; }
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
32
120
275da698697d config: template-ify INI
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
33 int UserId() const { return session.config.auth.anilist.user_id; }
275da698697d config: template-ify INI
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
34 void SetUserId(const int id) { session.config.auth.anilist.user_id = id; }
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
35
120
275da698697d config: template-ify INI
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
36 std::string AuthToken() const { return session.config.auth.anilist.auth_token; }
275da698697d config: template-ify INI
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
37 void SetAuthToken(std::string const& auth_token) { session.config.auth.anilist.auth_token = auth_token; }
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
38
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
39 bool Authenticated() const { return !AuthToken().empty(); }
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
40 bool IsValid() const { return UserId() && Authenticated(); }
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
41 };
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
42
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
43 static Account account;
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
44
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
45 std::string SendRequest(std::string data) {
76
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 75
diff changeset
46 std::vector<std::string> headers = {"Authorization: Bearer " + account.AuthToken(), "Accept: application/json",
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
47 "Content-Type: application/json"};
77
6f7385bd334c *: update
Paper <mrpapersonic@gmail.com>
parents: 76
diff changeset
48 return Strings::ToUtf8String(HTTP::Post("https://graphql.anilist.co", data, headers));
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
49 }
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
50
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
51 nlohmann::json SendJSONRequest(nlohmann::json data) {
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
52 std::string request = SendRequest(data.dump());
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
53 if (request.empty()) {
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
54 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
55 return {};
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
56 }
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 auto ret = nlohmann::json::parse(request, nullptr, false);
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
59 if (ret.is_discarded()) {
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
60 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
61 return {};
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
62 }
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 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
65 for (const auto& error : ret.at("/errors"_json_pointer))
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
66 std::cerr << "[AniList] Received an error in response: " << JSON::GetString<std::string>(error, "/message"_json_pointer, "") << std::endl;
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
67
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
68 return {};
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
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
71 return ret;
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
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
74 void ParseListStatus(std::string status, Anime::Anime& anime) {
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
75 std::unordered_map<std::string, Anime::ListStatus> map = {
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
76 {"CURRENT", Anime::ListStatus::CURRENT },
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
77 {"PLANNING", Anime::ListStatus::PLANNING },
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
78 {"COMPLETED", Anime::ListStatus::COMPLETED},
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
79 {"DROPPED", Anime::ListStatus::DROPPED },
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
80 {"PAUSED", Anime::ListStatus::PAUSED }
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
81 };
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
82
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
83 if (status == "REPEATING") {
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
84 anime.SetUserIsRewatching(true);
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
85 anime.SetUserStatus(Anime::ListStatus::CURRENT);
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
86 return;
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
87 }
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
88
47
d8eb763e6661 information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents: 44
diff changeset
89 if (map.find(status) == map.end()) {
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
90 anime.SetUserStatus(Anime::ListStatus::NOT_IN_LIST);
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
91 return;
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
92 }
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
93
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
94 anime.SetUserStatus(map[status]);
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
95 }
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
96
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
97 std::string ListStatusToString(const Anime::Anime& anime) {
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
98 if (anime.GetUserIsRewatching())
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
99 return "REWATCHING";
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
100
70
64e5f427c6a2 services/anilist: remove unordered_map usage for enum classes
Paper <mrpapersonic@gmail.com>
parents: 66
diff changeset
101 switch (anime.GetUserStatus()) {
76
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 75
diff changeset
102 case Anime::ListStatus::PLANNING: return "PLANNING";
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 75
diff changeset
103 case Anime::ListStatus::COMPLETED: return "COMPLETED";
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 75
diff changeset
104 case Anime::ListStatus::DROPPED: return "DROPPED";
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 75
diff changeset
105 case Anime::ListStatus::PAUSED: return "PAUSED";
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 75
diff changeset
106 default: break;
70
64e5f427c6a2 services/anilist: remove unordered_map usage for enum classes
Paper <mrpapersonic@gmail.com>
parents: 66
diff changeset
107 }
64e5f427c6a2 services/anilist: remove unordered_map usage for enum classes
Paper <mrpapersonic@gmail.com>
parents: 66
diff changeset
108 return "CURRENT";
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
109 }
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
110
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
111 void ParseTitle(const nlohmann::json& json, Anime::Anime& anime) {
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
112 anime.SetNativeTitle(JSON::GetString<std::string>(json, "/native"_json_pointer, ""));
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
113 anime.SetEnglishTitle(JSON::GetString<std::string>(json, "/english"_json_pointer, ""));
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
114 anime.SetRomajiTitle(JSON::GetString<std::string>(json, "/romaji"_json_pointer, ""));
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
115 }
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
116
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
117 int ParseMediaJson(const nlohmann::json& json) {
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
118 int id = JSON::GetNumber(json, "/id"_json_pointer);
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
119 if (!id)
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
120 return 0;
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
121
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
122 Anime::Anime& anime = Anime::db.items[id];
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
123 anime.SetId(id);
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
124
11
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
125 ParseTitle(json.at("/title"_json_pointer), anime);
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
126
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
127 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
128 anime.SetFormat(Translate::AniList::ToSeriesFormat(JSON::GetString<std::string>(json, "/format"_json_pointer, "")));
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
129
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
130 anime.SetAiringStatus(Translate::AniList::ToSeriesStatus(JSON::GetString<std::string>(json, "/status"_json_pointer, "")));
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
131
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
132 anime.SetAirDate(Date(json["/startDate"_json_pointer]));
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
133
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
134 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
135
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
136 anime.SetAudienceScore(JSON::GetNumber(json, "/averageScore"_json_pointer, 0));
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
137 anime.SetSeason(Translate::AniList::ToSeriesSeason(JSON::GetString<std::string>(json, "/season"_json_pointer, "")));
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
138 anime.SetDuration(JSON::GetNumber(json, "/duration"_json_pointer, 0));
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
139 anime.SetSynopsis(Strings::TextifySynopsis(JSON::GetString<std::string>(json, "/description"_json_pointer, "")));
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
140
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
141 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
142 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
143
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
144 return id;
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
145 }
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
146
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
147 int ParseListItem(const nlohmann::json& json) {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
148 int id = ParseMediaJson(json["media"]);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
149
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
150 Anime::Anime& anime = Anime::db.items[id];
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
151
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
152 anime.AddToUserList();
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
153
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
154 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
155 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
156 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
157 anime.SetUserNotes(JSON::GetString<std::string>(json, "/notes"_json_pointer, ""));
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
158
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
159 anime.SetUserDateStarted(Date(json["/startedAt"_json_pointer]));
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
160 anime.SetUserDateCompleted(Date(json["/completedAt"_json_pointer]));
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
161
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
162 anime.SetUserTimeUpdated(JSON::GetNumber(json, "/updatedAt"_json_pointer, 0));
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
163
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
164 return id;
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
165 }
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
166
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
167 int ParseList(const nlohmann::json& json) {
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
168 for (const auto& entry : json["entries"].items()) {
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
169 ParseListItem(entry.value());
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
170 }
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
171 return 1;
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
172 }
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
173
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
174 int GetAnimeList() {
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
175 if (!account.IsValid()) {
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
176 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
177 return 0;
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
178 }
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
179
183
01d259b9c89f pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents: 175
diff changeset
180 /* 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
181 constexpr std::string_view query = "query ($id: Int) {\n"
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
182 " MediaListCollection (userId: $id, type: ANIME) {\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
183 " lists {\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
184 " name\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
185 " entries {\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
186 " score\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
187 " notes\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
188 " status\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
189 " progress\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
190 " startedAt {\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
191 " year\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
192 " month\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
193 " day\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
194 " }\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
195 " completedAt {\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
196 " year\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
197 " month\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
198 " day\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
199 " }\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
200 " updatedAt\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
201 " media {\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
202 " coverImage {\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
203 " large\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
204 " }\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
205 " id\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
206 " title {\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
207 " romaji\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
208 " english\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
209 " native\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
210 " }\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
211 " format\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
212 " status\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
213 " averageScore\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
214 " season\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
215 " startDate {\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
216 " year\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
217 " month\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
218 " day\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
219 " }\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
220 " genres\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
221 " episodes\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
222 " duration\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
223 " synonyms\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
224 " description(asHtml: false)\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
225 " }\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
226 " }\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
227 " }\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
228 " }\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
229 "}\n";
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
230 // clang-format off
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
231 nlohmann::json json = {
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
232 {"query", query},
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
233 {"variables", {
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
234 {"id", account.UserId()}
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
235 }}
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
236 };
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
237 // clang-format on
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
238
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
239 auto res = SendJSONRequest(json);
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
240
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
241 for (const auto& list : res["data"]["MediaListCollection"]["lists"].items()) {
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
242 ParseList(list.value());
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
243 }
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
244 return 1;
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
245 }
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
246
52
0c4138de2ea7 anime list: we are finally read-write
Paper <mrpapersonic@gmail.com>
parents: 48
diff changeset
247 int UpdateAnimeEntry(int id) {
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
248 /**
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
249 * possible values:
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
250 *
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
251 * int mediaId,
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
252 * MediaListStatus status,
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
253 * float score,
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
254 * int scoreRaw,
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
255 * int progress,
184
09492158bcc5 anime: etc. comments and changes
Paper <mrpapersonic@gmail.com>
parents: 183
diff changeset
256 * int progressVolumes, // manga-specific.
09492158bcc5 anime: etc. comments and changes
Paper <mrpapersonic@gmail.com>
parents: 183
diff changeset
257 * int repeat, // rewatch
09492158bcc5 anime: etc. comments and changes
Paper <mrpapersonic@gmail.com>
parents: 183
diff changeset
258 * int priority,
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
259 * bool private,
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
260 * string notes,
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
261 * bool hiddenFromStatusLists,
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
262 * string[] customLists,
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
263 * float[] advancedScores,
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
264 * Date startedAt,
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
265 * Date completedAt
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
266 **/
52
0c4138de2ea7 anime list: we are finally read-write
Paper <mrpapersonic@gmail.com>
parents: 48
diff changeset
267 Anime::Anime& anime = Anime::db.items[id];
184
09492158bcc5 anime: etc. comments and changes
Paper <mrpapersonic@gmail.com>
parents: 183
diff changeset
268 if (!anime.IsInUserList())
09492158bcc5 anime: etc. comments and changes
Paper <mrpapersonic@gmail.com>
parents: 183
diff changeset
269 return 0;
09492158bcc5 anime: etc. comments and changes
Paper <mrpapersonic@gmail.com>
parents: 183
diff changeset
270
183
01d259b9c89f pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents: 175
diff changeset
271 constexpr std::string_view query = "mutation ($media_id: Int, $progress: Int, $status: MediaListStatus, $score: Int, "
184
09492158bcc5 anime: etc. comments and changes
Paper <mrpapersonic@gmail.com>
parents: 183
diff changeset
272 "$notes: String, $start: FuzzyDateInput, $comp: FuzzyDateInput, $repeat: Int) {\n"
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
273 " SaveMediaListEntry (mediaId: $media_id, progress: $progress, status: $status, "
184
09492158bcc5 anime: etc. comments and changes
Paper <mrpapersonic@gmail.com>
parents: 183
diff changeset
274 "scoreRaw: $score, notes: $notes, startedAt: $start, completedAt: $comp, repeat: $repeat) {\n"
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
275 " id\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
276 " }\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
277 "}\n";
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
278 // clang-format off
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
279 nlohmann::json json = {
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
280 {"query", query},
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
281 {"variables", {
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
282 {"media_id", anime.GetId()},
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
283 {"progress", anime.GetUserProgress()},
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
284 {"status", ListStatusToString(anime)},
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
285 {"score", anime.GetUserScore()},
77
6f7385bd334c *: update
Paper <mrpapersonic@gmail.com>
parents: 76
diff changeset
286 {"notes", anime.GetUserNotes()},
6f7385bd334c *: update
Paper <mrpapersonic@gmail.com>
parents: 76
diff changeset
287 {"start", anime.GetUserDateStarted().GetAsAniListJson()},
184
09492158bcc5 anime: etc. comments and changes
Paper <mrpapersonic@gmail.com>
parents: 183
diff changeset
288 {"comp", anime.GetUserDateCompleted().GetAsAniListJson()},
09492158bcc5 anime: etc. comments and changes
Paper <mrpapersonic@gmail.com>
parents: 183
diff changeset
289 {"repeat", anime.GetUserRewatchedTimes()}
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
290 }}
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
291 };
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
292 // clang-format on
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
293
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
294 auto ret = SendJSONRequest(json);
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
295
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
296 return JSON::GetNumber(ret, "/data/SaveMediaListEntry/id"_json_pointer, 0);
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
297 }
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
298
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
299 int ParseUser(const nlohmann::json& json) {
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
300 account.SetUsername(JSON::GetString<std::string>(json, "/name"_json_pointer, ""));
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
301 account.SetUserId(JSON::GetNumber(json, "/id"_json_pointer, 0));
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
302 return account.UserId();
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
303 }
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
304
44
619cbd6e69f9 filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents: 36
diff changeset
305 bool AuthorizeUser() {
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
306 /* Prompt for PIN */
36
2743011a6042 *: mass update
Paper <mrpapersonic@gmail.com>
parents: 15
diff changeset
307 QDesktopServices::openUrl(
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
308 QUrl("https://anilist.co/api/v2/oauth/authorize?client_id=" CLIENT_ID "&response_type=token"));
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
309
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
310 bool ok;
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
311 QString token = QInputDialog::getText(
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
312 0, "Credentials needed!", "Please enter the code given to you after logging in to AniList:", QLineEdit::Normal,
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
313 "", &ok);
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
314
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
315 if (!ok || token.isEmpty())
44
619cbd6e69f9 filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents: 36
diff changeset
316 return false;
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
317
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
318 account.SetAuthToken(Strings::ToUtf8String(token));
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
319
183
01d259b9c89f pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents: 175
diff changeset
320 constexpr std::string_view query = "query {\n"
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
321 " Viewer {\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
322 " id\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
323 " name\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
324 " mediaListOptions {\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
325 " scoreFormat\n" // this will be used... eventually
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
326 " }\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
327 " }\n"
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
328 "}\n";
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
329 nlohmann::json json = {
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
330 {"query", query}
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
331 };
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
332
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
333 auto ret = SendJSONRequest(json);
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
334
74
5ccb99bfa605 fix regressions on macOS
Paper <mrpapersonic@gmail.com>
parents: 70
diff changeset
335 ParseUser(ret["data"]["Viewer"]);
44
619cbd6e69f9 filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents: 36
diff changeset
336 return true;
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
337 }
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
338
63
3d2decf093bb *: fix many clang warnings
Paper <mrpapersonic@gmail.com>
parents: 52
diff changeset
339 } // namespace AniList
3d2decf093bb *: fix many clang warnings
Paper <mrpapersonic@gmail.com>
parents: 52
diff changeset
340 } // namespace Services