annotate src/services/kitsu.cc @ 318:3b355fa948c7

config: use TOML instead of INI unfortunately, INI is not enough, and causes some paths including semicolons to break with our current storage of the library folders. so, I decided to switch to TOML which does support real arrays...
author Paper <paper@paper.us.eu.org>
date Wed, 12 Jun 2024 05:25:41 -0400
parents b1f4d1867ab1
children d928ec7b6a0d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
317
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
1 #include "services/anilist.h"
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
2 #include "core/anime.h"
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
3 #include "core/anime_db.h"
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
4 #include "core/date.h"
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
5 #include "core/config.h"
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
6 #include "core/http.h"
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
7 #include "core/json.h"
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
8 #include "core/session.h"
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
9 #include "core/strings.h"
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
10 #include "core/time.h"
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
11 #include "gui/translate/anilist.h"
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
12
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
13 #include <QByteArray>
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
14 #include <QDate>
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
15 #include <QDesktopServices>
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
16 #include <QInputDialog>
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
17 #include <QLineEdit>
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
18 #include <QMessageBox>
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
19 #include <QUrl>
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
20
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
21 #include <chrono>
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
22 #include <exception>
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
23 #include <string_view>
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
24
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
25 #include <iostream>
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
26
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
27 using namespace nlohmann::literals::json_literals;
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
28
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
29 static constexpr std::string_view CLIENT_ID = "dd031b32d2f56c990b1425efe6c42ad847e7fe3ab46bf1299f05ecd856bdb7dd";
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
30 static constexpr std::string_view CLIENT_SECRET = "54d7307928f63414defd96399fc31ba847961ceaecef3a5fd93144e960c0e151";
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
31
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
32 static constexpr std::string_view BASE_API_PATH = "https://kitsu.io/api/edge";
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
33 static constexpr std::string_view OAUTH_PATH = "https://kitsu.io/api/oauth/token";
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
34
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
35 namespace Services {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
36 namespace Kitsu {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
37
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
38 /* This nifty little function basically handles authentication AND reauthentication. */
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
39 static bool SendAuthRequest(const nlohmann::json& data) {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
40 static const std::vector<std::string> headers = {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
41 {"Content-Type: application/json"}
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
42 };
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
43
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
44 const std::string ret = Strings::ToUtf8String(HTTP::Request(std::string(OAUTH_PATH), headers, data.dump(), HTTP::Type::Post));
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
45 if (ret.empty()) {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
46 session.SetStatusBar("Kitsu: Request returned empty data!");
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
47 return false;
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
48 }
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
49
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
50 nlohmann::json result;
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
51 try {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
52 result = nlohmann::json::parse(ret, nullptr, false);
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
53 } catch (const std::exception& ex) {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
54 session.SetStatusBar(std::string("Kitsu: Failed to parse authorization data with error \"") + ex.what() + "\"!");
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
55 return false;
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
56 }
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
57
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
58 if (result.contains("/error"_json_pointer)) {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
59 std::string status = "Kitsu: Failed with error \"";
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
60 status += result["/error"_json_pointer].get<std::string>();
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
61
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
62 if (result.contains("/error_description"_json_pointer)) {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
63 status += "\" and description \"";
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
64 status += result["/error_description"_json_pointer].get<std::string>();
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
65 }
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
66
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
67 status += "\"!";
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
68
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
69 session.SetStatusBar(status);
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
70 return false;
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
71 }
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
72
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
73 const std::vector<nlohmann::json::json_pointer> required = {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
74 "/access_token"_json_pointer,
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
75 "/created_at"_json_pointer,
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
76 "/expires_in"_json_pointer,
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
77 "/refresh_token"_json_pointer,
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
78 "/scope"_json_pointer,
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
79 "/token_type"_json_pointer
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
80 };
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
81
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
82 for (const auto& ptr : required) {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
83 if (!result.contains(ptr)) {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
84 session.SetStatusBar("Kitsu: Authorization request returned bad data!");
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
85 return false;
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
86 }
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
87 }
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
88
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
89 session.config.auth.kitsu.access_token = result["/access_token"_json_pointer].get<std::string>();
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
90 session.config.auth.kitsu.access_token_expiration
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
91 = result["/created_at"_json_pointer].get<Time::Timestamp>();
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
92 + result["/expires_in"_json_pointer].get<Time::Timestamp>();
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
93 session.config.auth.kitsu.refresh_token = result["/refresh_token"_json_pointer].get<std::string>();
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
94
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
95 /* the next two are not that important */
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
96
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
97 return true;
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
98 }
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
99
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
100 static bool RefreshAccessToken(std::string& access_token, const std::string& refresh_token) {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
101 const nlohmann::json request = {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
102 {"grant_type", "refresh_token"},
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
103 {"refresh_token", refresh_token}
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
104 };
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
105
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
106 if (!SendAuthRequest(request))
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
107 return false;
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
108
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
109 return true;
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
110 }
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
111
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
112 /* ----------------------------------------------------------------------------- */
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
113
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
114 static std::optional<std::string> AccountAccessToken() {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
115 auto& auth = session.config.auth.kitsu;
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
116
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
117 if (Time::GetSystemTime() >= session.config.auth.kitsu.access_token_expiration)
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
118 if (!RefreshAccessToken(auth.access_token, auth.refresh_token))
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
119 return std::nullopt;
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
120
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
121 return auth.access_token;
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
122 }
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
123
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
124 /* ----------------------------------------------------------------------------- */
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
125
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
126 static std::optional<std::string> SendRequest(const std::string& path, const std::map<std::string, std::string>& params) {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
127 std::optional<std::string> token = AccountAccessToken();
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
128 if (!token)
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
129 return std::nullopt;
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
130
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
131 const std::vector<std::string> headers = {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
132 "Accept: application/vnd.api+json",
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
133 "Authorization: Bearer " + token.value(),
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
134 "Content-Type: application/vnd.api+json"
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
135 };
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
136
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
137 const std::string url = HTTP::EncodeParamsList(std::string(BASE_API_PATH) + path, params);
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
138
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
139 return Strings::ToUtf8String(HTTP::Request(url, headers, "", HTTP::Type::Get));
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
140 }
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
141
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
142 static void ParseTitleJson(Anime::Anime& anime, const nlohmann::json& json) {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
143 static const std::map<std::string, Anime::TitleLanguage> lookup = {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
144 {"en", Anime::TitleLanguage::English},
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
145 {"en_jp", Anime::TitleLanguage::Romaji},
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
146 {"ja_jp", Anime::TitleLanguage::Native}
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
147 };
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
148
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
149 for (const auto& [string, title] : lookup)
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
150 if (json.contains(string))
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
151 anime.SetTitle(title, json[string].get<std::string>());
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
152 }
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
153
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
154 static void ParseSubtype(Anime::Anime& anime, const std::string& str) {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
155 static const std::map<std::string, Anime::SeriesFormat> lookup = {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
156 {"ONA", Anime::SeriesFormat::Ona},
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
157 {"OVA", Anime::SeriesFormat::Ova},
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
158 {"TV", Anime::SeriesFormat::Tv},
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
159 {"movie", Anime::SeriesFormat::Movie},
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
160 {"music", Anime::SeriesFormat::Music},
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
161 {"special", Anime::SeriesFormat::Special}
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
162 };
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
163
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
164 if (lookup.find(str) == lookup.end())
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
165 return;
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
166
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
167 anime.SetFormat(lookup.at(str));
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
168 }
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
169
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
170 static const std::string FAILED_TO_PARSE = "Kitsu: Failed to parse anime object!";
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
171
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
172 static int ParseAnimeJson(const nlohmann::json& json) {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
173 const std::string service_id = json["/id"_json_pointer].get<std::string>();
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
174 if (service_id.empty()) {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
175 session.SetStatusBar(FAILED_TO_PARSE);
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
176 return 0;
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
177 }
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
178
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
179 if (!json.contains("/attributes"_json_pointer)) {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
180 session.SetStatusBar(FAILED_TO_PARSE);
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
181 return 0;
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
182 }
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
183
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
184 const auto& attributes = json["/attributes"_json_pointer];
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
185
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
186 int id = Anime::db.LookupServiceIdOrUnused(Anime::Service::Kitsu, service_id);
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
187 if (!id) {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
188 session.SetStatusBar(FAILED_TO_PARSE);
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
189 return 0;
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
190 }
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
191
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
192 Anime::Anime& anime = Anime::db.items[id];
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
193
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
194 anime.SetId(id);
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
195 anime.SetServiceId(Anime::Service::Kitsu, service_id);
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
196 anime.SetSynopsis(attributes["/synopsis"_json_pointer].get<std::string>());
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
197 ParseTitleJson(anime, attributes["/titles"_json_pointer]);
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
198
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
199 // FIXME: parse abbreviatedTitles for synonyms??
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
200
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
201 anime.SetAudienceScore(JSON::GetNumber<double>(attributes, "/averageRating"_json_pointer));
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
202
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
203 if (attributes.contains("/startDate"_json_pointer))
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
204 anime.SetAirDate(attributes["/startDate"_json_pointer].get<std::string>());
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
205
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
206 // TODO: endDate
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
207
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
208 if (attributes.contains("/subtype"_json_pointer))
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
209 ParseSubtype(anime, attributes["/subtype"_json_pointer].get<std::string>());
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
210
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
211 anime.SetPosterUrl(attributes["/posterImage/original"_json_pointer].get<std::string>());
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
212 anime.SetEpisodes(attributes["/episodeCount"_json_pointer].get<int>());
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
213 anime.SetDuration(attributes["/episodeLength"_json_pointer].get<int>());
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
214
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
215 return id;
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
216 }
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
217
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
218 static int ParseLibraryJson(const nlohmann::json& json) {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
219 if (!json.contains("/relationships/anime/data"_json_pointer)
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
220 || !json.contains("/attributes"_json_pointer)
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
221 || !json.contains("/id"_json_pointer)) {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
222 session.SetStatusBar("Kitsu: Failed to parse library object!");
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
223 return 0;
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
224 }
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
225
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
226 int id = ParseAnimeJson(json["/relationships/anime/data"_json_pointer]);
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
227 if (!id)
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
228 return 0;
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
229
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
230 const auto& attributes = json["/attributes"_json_pointer];
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
231
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
232 const std::string library_id = json["/id"_json_pointer].get<std::string>();
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
233
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
234 Anime::Anime& anime = Anime::db.items[id];
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
235
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
236 anime.AddToUserList();
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
237
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
238 anime.SetUserId(library_id);
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
239 anime.SetUserDateStarted(Date(attributes["/startedAt"_json_pointer].get<std::string>()));
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
240 anime.SetUserDateCompleted(Date(attributes["/finishedAt"_json_pointer].get<std::string>()));
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
241 anime.SetUserNotes(attributes["/notes"_json_pointer].get<std::string>());
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
242 anime.SetUserProgress(attributes["/progress"_json_pointer].get<int>());
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
243 anime.SetUserScore(attributes["/ratingTwenty"_json_pointer].get<int>() * 5);
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
244 anime.SetUserIsPrivate(attributes["/private"_json_pointer].get<bool>());
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
245 anime.SetUserRewatchedTimes(attributes["/reconsumeCount"_json_pointer].get<int>());
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
246 anime.SetUserIsRewatching(attributes["/reconsuming"_json_pointer].get<bool>()); /* "reconsuming". really? */
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
247 // anime.SetUserStatus();
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
248 // anime.SetUserLastUpdated();
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
249
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
250 return id;
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
251 }
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
252
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
253 int GetAnimeList() {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
254 return 0;
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
255 }
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
256
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
257 /* unimplemented for now */
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
258 std::vector<int> Search(const std::string& search) {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
259 return {};
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
260 }
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
261
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
262 std::vector<int> GetSeason(Anime::SeriesSeason season, Date::Year year) {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
263 return {};
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
264 }
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
265
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
266 int UpdateAnimeEntry(int id) {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
267 return 0;
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
268 }
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
269
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
270 bool AuthorizeUser(const std::string& email, const std::string& password) {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
271 const nlohmann::json body = {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
272 {"grant_type", "password"},
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
273 {"username", email},
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
274 {"password", HTTP::UrlEncode(password)}
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
275 };
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
276
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
277 if (!SendAuthRequest(body))
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
278 return false;
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
279
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
280 static const std::map<std::string, std::string> params = {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
281 {"filter[self]", "true"}
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
282 };
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
283
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
284 std::optional<std::string> response = SendRequest("/users", params);
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
285 if (!response)
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
286 return false; // whuh?
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
287
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
288 nlohmann::json json;
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
289 try {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
290 json = nlohmann::json::parse(response.value());
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
291 } catch (const std::exception& ex) {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
292 session.SetStatusBar(std::string("Kitsu: Failed to parse user data with error \"") + ex.what() + "\"!");
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
293 return false;
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
294 }
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
295
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
296 if (!json.contains("/data/0/id"_json_pointer)) {
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
297 session.SetStatusBar("Kitsu: Failed to retrieve user ID!");
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
298 return false;
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
299 }
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
300
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
301 session.SetStatusBar("Kitsu: Successfully retrieved user data!");
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
302 session.config.auth.kitsu.user_id = json["/data/0/id"_json_pointer].get<std::string>();
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
303
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
304 return true;
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
305 }
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
306
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
307 } // namespace Kitsu
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
diff changeset
308 } // namespace Services