From ca49eef152db41ac30df2fd6a1b4631f81491b6b Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 2 Oct 2021 04:56:27 +0200 Subject: Show genre as reactions for mangadex and anilist --- src/plugins/Mangadex.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) (limited to 'src/plugins/Mangadex.cpp') diff --git a/src/plugins/Mangadex.cpp b/src/plugins/Mangadex.cpp index e57c6cd..3632ed5 100644 --- a/src/plugins/Mangadex.cpp +++ b/src/plugins/Mangadex.cpp @@ -88,6 +88,30 @@ namespace QuickMedia { return result; } + static void add_tags(const Json::Value &tags_json, BodyItem *body_item) { + if(!tags_json.isArray()) + return; + + for(const Json::Value &tag_json : tags_json) { + if(!tag_json.isObject()) + continue; + + const Json::Value &attributes_json = tag_json["attributes"]; + if(!attributes_json.isObject()) + continue; + + const Json::Value &name_json = attributes_json["name"]; + if(!name_json.isObject()) + continue; + + const Json::Value &en_name_json = name_json["en"]; + if(!en_name_json.isString()) + continue; + + body_item->add_reaction(en_name_json.asString(), nullptr); + } + } + enum class SearchType { TITLE, AUTHOR @@ -146,15 +170,50 @@ namespace QuickMedia { auto body_item = BodyItem::create(std::move(title)); body_item->url = id_json.asString(); + + std::string description; + + const Json::Value &status_json = attributes_json["status"]; + if(status_json.isString()) { + if(!description.empty()) + description += '\n'; + description += "Status: " + status_json.asString(); + } + + /* Commented out because its broken on mangadex. TODO: Uncomment when mangadex fixes this + const Json::Value &updated_at_json = attributes_json["updatedAt"]; + if(updated_at_json.isString()) { + if(!description.empty()) + description += '\n'; + const time_t unix_time = iso_utc_to_unix_time(updated_at_json.asCString()); + description += "Updated: " + unix_time_to_local_time_str(unix_time); + } + */ + + const Json::Value &last_chapter_json = attributes_json["lastChapter"]; + if(last_chapter_json.isString()) { + if(!description.empty()) + description += '\n'; + description += "Last chapter: " + last_chapter_json.asString(); + } + const Json::Value &description_json = attributes_json["description"]; if(description_json.isObject()) { const Json::Value &en_json = description_json["en"]; if(en_json.isString()) { - body_item->set_description(en_json.asString()); - body_item->set_description_color(get_theme().faded_text_color); + if(!description.empty()) + description += '\n'; + description += en_json.asString(); } } + if(!description.empty()) { + body_item->set_description(std::move(description)); + body_item->set_description_color(get_theme().faded_text_color); + } + + add_tags(attributes_json["tags"], body_item.get()); + std::string cover_art_filename = relationships_get_cover_art_filename(data_json["relationships"]); if(!cover_art_filename.empty()) body_item->thumbnail_url = "https://uploads.mangadex.org/covers/" + body_item->url + "/" + std::move(cover_art_filename) + ".256.jpg"; -- cgit v1.2.3