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/Body.cpp | 2 +- src/Utils.cpp | 2 +- src/plugins/AniList.cpp | 19 ++++++++----- src/plugins/MangaCombined.cpp | 3 +++ src/plugins/Mangadex.cpp | 63 +++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 79 insertions(+), 10 deletions(-) diff --git a/src/Body.cpp b/src/Body.cpp index ea43781..dffb3c9 100644 --- a/src/Body.cpp +++ b/src/Body.cpp @@ -109,7 +109,7 @@ namespace QuickMedia { top_cut_off(false), bottom_cut_off(false), item_background(sf::Vector2f(1.0f, 1.0f), 10.0f, get_theme().selected_color, rounded_rectangle_shader), - reaction_background(sf::Vector2f(1.0f, 1.0f), 10.0f, get_theme().shade_color, rounded_rectangle_shader), + reaction_background(sf::Vector2f(1.0f, 1.0f), 10.0f, body_theme == BODY_THEME_MINIMAL ? get_theme().shade_color : get_theme().background_color, rounded_rectangle_shader), rounded_rectangle_shader(rounded_rectangle_shader), rounded_rectangle_mask_shader(rounded_rectangle_mask_shader) { diff --git a/src/Utils.cpp b/src/Utils.cpp index 67c739b..3d87140 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -79,6 +79,6 @@ namespace QuickMedia { } sf::Vector2f vec2f_round(float x, float y) { - return { int(x), int(y) }; + return sf::Vector2f(int(x), int(y)); } } diff --git a/src/plugins/AniList.cpp b/src/plugins/AniList.cpp index 5043eb7..3559a81 100644 --- a/src/plugins/AniList.cpp +++ b/src/plugins/AniList.cpp @@ -241,6 +241,17 @@ query ($id: Int, $page: Int, $perPage: Int) { return result; } + static void add_genres(const Json::Value &genres_json, BodyItem *body_item) { + if(!genres_json.isArray()) + return; + + for(const Json::Value &genre_json : genres_json) { + if(!genre_json.isString()) + continue; + body_item->add_reaction(genre_json.asString(), nullptr); + } + } + static void description_remove_html(std::string &description) { string_replace_all(description, "", ""); string_replace_all(description, "", ""); @@ -374,12 +385,6 @@ query ($id: Int, $page: Int, $perPage: Int) { description += media_status_to_readable(status_json.asCString(), media_type); } - if(genres_json.isArray() && genres_json.size() > 0) { - if(!description.empty()) - description += '\n'; - description += "Genres: " + json_string_array_to_string(genres_json); - } - if(description_json.isString()) { if(!description.empty()) description += "\n\n"; @@ -387,6 +392,7 @@ query ($id: Int, $page: Int, $perPage: Int) { std::string synopsis = description_json.asString(); description_remove_html(synopsis); + synopsis = strip(synopsis); description += std::move(synopsis); } @@ -404,6 +410,7 @@ query ($id: Int, $page: Int, $perPage: Int) { body_item->thumbnail_url = cover_img_sized_json.asString(); } body_item->thumbnail_size = thumbnail_size_get_prediced_size(thumbnail_size); + add_genres(genres_json, body_item.get()); return body_item; } diff --git a/src/plugins/MangaCombined.cpp b/src/plugins/MangaCombined.cpp index c7fdd13..0742562 100644 --- a/src/plugins/MangaCombined.cpp +++ b/src/plugins/MangaCombined.cpp @@ -23,6 +23,9 @@ namespace QuickMedia { int accumulated_sleep_time = 0; while(true) { + if(program_is_dead_in_current_thread()) + break; + size_t num_dead_threads = 0; for(size_t i = 0; i < search_threads.size(); ++i) { auto &search_thread = search_threads[i]; 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