aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2023-09-30 00:15:56 +0200
committerdec05eba <dec05eba@protonmail.com>2023-09-30 00:15:56 +0200
commit31c90080ff3175050961d68451ece26e41a7f1f9 (patch)
tree17075ff1f2502d8f1d11915fff2956092f584430 /src/plugins
parentaab778b4f4cca2aeda13824ceb377edfc8ae923c (diff)
Anilist: add studios/producers info to details page
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/AniList.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/plugins/AniList.cpp b/src/plugins/AniList.cpp
index a41e644..50b1a86 100644
--- a/src/plugins/AniList.cpp
+++ b/src/plugins/AniList.cpp
@@ -73,6 +73,12 @@ query ($id: Int) {
romaji
}
synonyms
+ studios (sort: NAME) {
+ nodes {
+ name
+ isAnimationStudio
+ }
+ }
}
}
)END";
@@ -284,6 +290,31 @@ query ($id: Int, $page: Int, $perPage: Int) {
return {0, 0};
}
+ static void get_studios_and_producers(const Json::Value &nodes_json, std::string &studios, std::string &producers) {
+ if(!nodes_json.isArray())
+ return;
+
+ for(const Json::Value &node_json : nodes_json) {
+ if(!node_json.isObject())
+ continue;
+
+ const Json::Value &name_json = node_json["name"];
+ const Json::Value &is_animation_studio_json = node_json["isAnimationStudio"];
+ if(!name_json.isString() || !is_animation_studio_json.isBool())
+ continue;
+
+ if(is_animation_studio_json.asBool()) {
+ if(!studios.empty())
+ studios += "\n";
+ studios += name_json.asString();
+ } else {
+ if(!producers.empty())
+ producers += "\n";
+ producers += name_json.asString();
+ }
+ }
+ }
+
// Returns nullptr on error
static std::shared_ptr<BodyItem> media_json_to_body_item(const Json::Value &media_json, ThumbnailSize thumbnail_size, AniListMediaType &media_type) {
if(!media_json.isObject())
@@ -307,6 +338,7 @@ query ($id: Int, $page: Int, $perPage: Int) {
const Json::Value &duration_json = media_json["duration"];
const Json::Value &genres_json = media_json["genres"];
const Json::Value &description_json = media_json["description"];
+ const Json::Value &studios_json = media_json["studios"];
const Json::Value &romaji_title_json = title_json["romaji"];
if(!romaji_title_json.isString())
@@ -386,6 +418,26 @@ query ($id: Int, $page: Int, $perPage: Int) {
description += media_status_to_readable(status_json.asCString(), media_type);
}
+ if(studios_json.isObject()) {
+ std::string studios;
+ std::string producers;
+ get_studios_and_producers(studios_json["nodes"], studios, producers);
+
+ if(!studios.empty()) {
+ if(!description.empty())
+ description += "\n\n";
+ description += "Studios:\n";
+ description.append(studios);
+ }
+
+ if(!producers.empty()) {
+ if(!description.empty())
+ description += "\n\n";
+ description += "Producers:\n";
+ description.append(producers);
+ }
+ }
+
if(description_json.isString()) {
if(!description.empty())
description += "\n\n";