diff src/services/anilist.cc @ 413:192da585a0a8 default tip

*: fix formatting the clang-format file was broken andjust using LLVM defaults. now it's fixed and is more in line with what I actually prefer my code to look like -- esp. with regards to tabulators
author Paper <paper@tflc.us>
date Sat, 25 Jul 2026 14:54:32 -0400
parents 02a670a8e1c4
children
line wrap: on
line diff
--- a/src/services/anilist.cc	Sat Jul 25 14:33:03 2026 -0400
+++ b/src/services/anilist.cc	Sat Jul 25 14:54:32 2026 -0400
@@ -73,15 +73,15 @@
 static std::optional<nlohmann::json> SendJSONRequest(const nlohmann::json &data)
 {
 	std::vector<std::string> headers = {
-	    "Accept: application/json",
-	    "Content-Type: application/json",
+		"Accept: application/json",
+		"Content-Type: application/json",
 	};
 
 	if (!session.config.auth.anilist.auth_token.empty())
 		headers.push_back("Authorization: Bearer " + session.config.auth.anilist.auth_token);
 
 	const std::string response =
-	    Strings::ToUtf8String(HTTP::Request("https://graphql.anilist.co", headers, data.dump(), HTTP::Type::Post));
+		Strings::ToUtf8String(HTTP::Request("https://graphql.anilist.co", headers, data.dump(), HTTP::Type::Post));
 	if (response.empty()) {
 		session.SetStatusBar(Strings::Translate("AniList: JSON request returned an empty result!"));
 		return std::nullopt;
@@ -93,14 +93,14 @@
 		out = nlohmann::json::parse(response);
 	} catch (const std::exception &ex) {
 		session.SetStatusBar(
-		    fmt::format(Strings::Translate("AniList: Failed to parse request JSON with error \"{}\"!"), ex.what()));
+			fmt::format(Strings::Translate("AniList: Failed to parse request JSON with error \"{}\"!"), ex.what()));
 		return std::nullopt;
 	}
 
 	if (out.contains("/errors"_json_pointer) && out.at("/errors"_json_pointer).is_array()) {
 		for (const auto &error : out.at("/errors"_json_pointer))
 			std::cerr << "AniList: Received an error in response: "
-			          << JSON::GetString<std::string>(error, "/message"_json_pointer, "") << std::endl;
+					  << JSON::GetString<std::string>(error, "/message"_json_pointer, "") << std::endl;
 
 		session.SetStatusBar(Strings::Translate("AniList: Received an error in response!"));
 		return std::nullopt;
@@ -112,11 +112,11 @@
 static void ParseListStatus(std::string status, Anime::Anime &anime)
 {
 	static const std::unordered_map<std::string, Anime::ListStatus> map = {
-	    {"CURRENT",   Anime::ListStatus::Current  },
-	    {"PLANNING",  Anime::ListStatus::Planning },
-	    {"COMPLETED", Anime::ListStatus::Completed},
-	    {"DROPPED",   Anime::ListStatus::Dropped  },
-	    {"PAUSED",    Anime::ListStatus::Paused   }
+		{"CURRENT",   Anime::ListStatus::Current  },
+        {"PLANNING",  Anime::ListStatus::Planning },
+		{"COMPLETED", Anime::ListStatus::Completed},
+        {"DROPPED",   Anime::ListStatus::Dropped  },
+		{"PAUSED",    Anime::ListStatus::Paused   }
     };
 
 	if (status == "REPEATING") {
@@ -156,9 +156,9 @@
 static void ParseTitle(const nlohmann::json &json, Anime::Anime &anime)
 {
 	static const std::unordered_map<Anime::TitleLanguage, nlohmann::json::json_pointer> map = {
-	    {Anime::TitleLanguage::Native,  "/native"_json_pointer },
-	    {Anime::TitleLanguage::English, "/english"_json_pointer},
-	    {Anime::TitleLanguage::Romaji,  "/romaji"_json_pointer },
+		{Anime::TitleLanguage::Native,  "/native"_json_pointer },
+		{Anime::TitleLanguage::English, "/english"_json_pointer},
+		{Anime::TitleLanguage::Romaji,  "/romaji"_json_pointer },
 	};
 
 	for (const auto &[language, ptr] : map)
@@ -194,14 +194,14 @@
 	anime.SetFormat(Translate::AniList::ToSeriesFormat(JSON::GetString<std::string>(json, "/format"_json_pointer, "")));
 
 	anime.SetAiringStatus(
-	    Translate::AniList::ToSeriesStatus(JSON::GetString<std::string>(json, "/status"_json_pointer, "")));
+		Translate::AniList::ToSeriesStatus(JSON::GetString<std::string>(json, "/status"_json_pointer, "")));
 
 	if (json.contains("/startDate"_json_pointer) && json["/startDate"_json_pointer].is_object())
 		anime.SetStartedDate(Date(json["/startDate"_json_pointer]));
 
 	anime.SetCompletedDate(json.contains("/endDate"_json_pointer) && json["/endDate"_json_pointer].is_object()
-	                           ? Date(json["/endDate"_json_pointer])
-	                           : anime.GetStartedDate());
+							   ? Date(json["/endDate"_json_pointer])
+							   : anime.GetStartedDate());
 
 	anime.SetPosterUrl(JSON::GetString<std::string>(json, "/coverImage/large"_json_pointer, ""));
 
@@ -270,30 +270,30 @@
 	auto &auth = session.config.auth.anilist;
 
 	static constexpr std::string_view query = "query ($id: Int) {\n"
-	                                          "  MediaListCollection (userId: $id, type: ANIME) {\n"
-	                                          "    lists {\n"
-	                                          "      name\n"
-	                                          "      entries {\n"
-	                                          "        score\n"
-	                                          "        notes\n"
-	                                          "        status\n"
-	                                          "        progress\n"
-	                                          "        startedAt {\n"
-	                                          "          year\n"
-	                                          "          month\n"
-	                                          "          day\n"
-	                                          "        }\n"
-	                                          "        completedAt {\n"
-	                                          "          year\n"
-	                                          "          month\n"
-	                                          "          day\n"
-	                                          "        }\n"
-	                                          "        updatedAt\n"
-	                                          "        media {\n" MEDIA_FIELDS "        }\n"
-	                                          "      }\n"
-	                                          "    }\n"
-	                                          "  }\n"
-	                                          "}\n";
+											  "  MediaListCollection (userId: $id, type: ANIME) {\n"
+											  "    lists {\n"
+											  "      name\n"
+											  "      entries {\n"
+											  "        score\n"
+											  "        notes\n"
+											  "        status\n"
+											  "        progress\n"
+											  "        startedAt {\n"
+											  "          year\n"
+											  "          month\n"
+											  "          day\n"
+											  "        }\n"
+											  "        completedAt {\n"
+											  "          year\n"
+											  "          month\n"
+											  "          day\n"
+											  "        }\n"
+											  "        updatedAt\n"
+											  "        media {\n" MEDIA_FIELDS "        }\n"
+											  "      }\n"
+											  "    }\n"
+											  "  }\n"
+											  "}\n";
 
 	// clang-format off
 	nlohmann::json request = {
@@ -330,10 +330,10 @@
 std::vector<int> Search(const std::string &search)
 {
 	static constexpr std::string_view query = "query ($search: String) {\n"
-	                                          "  Page (page: 1, perPage: 50) {\n"
-	                                          "    media (search: $search, type: ANIME) {\n" MEDIA_FIELDS "    }\n"
-	                                          "  }\n"
-	                                          "}\n";
+											  "  Page (page: 1, perPage: 50) {\n"
+											  "    media (search: $search, type: ANIME) {\n" MEDIA_FIELDS "    }\n"
+											  "  }\n"
+											  "}\n";
 
 	// clang-format off
 	nlohmann::json json = {
@@ -363,31 +363,31 @@
 bool GetSeason(Anime::Season season)
 {
 	static constexpr std::string_view query =
-	    "query ($season: MediaSeason!, $season_year: Int!, $page: Int) {\n"
-	    "  Page(page: $page) {\n"
-	    "    media(season: $season, seasonYear: $season_year, type: ANIME, sort: START_DATE) {\n" MEDIA_FIELDS "    }\n"
-	    "    pageInfo {\n"
-	    "      total\n"
-	    "      perPage\n"
-	    "      currentPage\n"
-	    "      lastPage\n"
-	    "      hasNextPage\n"
-	    "    }\n"
-	    "  }\n"
-	    "}\n";
+		"query ($season: MediaSeason!, $season_year: Int!, $page: Int) {\n"
+		"  Page(page: $page) {\n"
+		"    media(season: $season, seasonYear: $season_year, type: ANIME, sort: START_DATE) {\n" MEDIA_FIELDS "    }\n"
+		"    pageInfo {\n"
+		"      total\n"
+		"      perPage\n"
+		"      currentPage\n"
+		"      lastPage\n"
+		"      hasNextPage\n"
+		"    }\n"
+		"  }\n"
+		"}\n";
 
 	int page = 0;
 	bool has_next_page = true;
 
 	while (has_next_page) {
 		nlohmann::json json = {
-		    {"query",     query},
-		    {"variables",
-		     {
-		         {"season", Translate::AniList::ToString(season.season)},
-		         {"season_year", Strings::ToUtf8String(season.year)},
-		         {"page", page},
-		     }		         },
+			{"query",     query},
+			{"variables",
+             {
+					{"season", Translate::AniList::ToString(season.season)},
+					{"season_year", Strings::ToUtf8String(season.year)},
+					{"page", page},
+				}              },
 		};
 
 		const std::optional<nlohmann::json> res = SendJSONRequest(json);
@@ -418,13 +418,13 @@
 		return 0;
 
 	static constexpr std::string_view query =
-	    "mutation ($media_id: Int, $progress: Int, $status: MediaListStatus, $score: Int, $notes: String,"
-	    "     $start: FuzzyDateInput, $comp: FuzzyDateInput, $repeat: Int) {\n"
-	    "  SaveMediaListEntry (mediaId: $media_id, progress: $progress, status: $status, scoreRaw: $score,"
-	    "        notes: $notes, startedAt: $start, completedAt: $comp, repeat: $repeat) {\n"
-	    "    id\n"
-	    "  }\n"
-	    "}\n";
+		"mutation ($media_id: Int, $progress: Int, $status: MediaListStatus, $score: Int, $notes: String,"
+		"     $start: FuzzyDateInput, $comp: FuzzyDateInput, $repeat: Int) {\n"
+		"  SaveMediaListEntry (mediaId: $media_id, progress: $progress, status: $status, scoreRaw: $score,"
+		"        notes: $notes, startedAt: $start, completedAt: $comp, repeat: $repeat) {\n"
+		"    id\n"
+		"  }\n"
+		"}\n";
 	// clang-format off
 	nlohmann::json json = {
 		{"query", query},
@@ -465,12 +465,11 @@
 
 	/* Prompt for PIN */
 	QDesktopServices::openUrl(QUrl(Strings::ToQString(
-	    "https://anilist.co/api/v2/oauth/authorize?client_id=" + std::string(CLIENT_ID) + "&response_type=token")));
+		"https://anilist.co/api/v2/oauth/authorize?client_id=" + std::string(CLIENT_ID) + "&response_type=token")));
 
 	bool ok;
-	QString token = QInputDialog::getText(
-	    0, "Credentials needed!", "Please enter the code given to you after logging in to AniList:", QLineEdit::Normal,
-	    "", &ok);
+	QString token = QInputDialog::getText(0, "Credentials needed!",
+		"Please enter the code given to you after logging in to AniList:", QLineEdit::Normal, "", &ok);
 
 	if (!ok || token.isEmpty())
 		return false;
@@ -480,13 +479,13 @@
 	session.SetStatusBar(Strings::Translate("AniList: Requesting user ID..."));
 
 	static constexpr std::string_view query = "query {\n"
-	                                          "  Viewer {\n"
-	                                          "    id\n"
-	                                          "  }\n"
-	                                          "}\n";
+											  "  Viewer {\n"
+											  "    id\n"
+											  "  }\n"
+											  "}\n";
 
 	nlohmann::json json = {
-	    {"query", query}
+		{"query", query}
     };
 
 	/* SendJSONRequest handles status errors */