From 51aa9384f7cf3ba33430ab7cade60ccdfbe06943 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 26 Aug 2021 05:45:49 +0200 Subject: Mangadex: fix missing thumbnails --- src/plugins/Mangadex.cpp | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/plugins/Mangadex.cpp b/src/plugins/Mangadex.cpp index 5b8debd..1553d82 100644 --- a/src/plugins/Mangadex.cpp +++ b/src/plugins/Mangadex.cpp @@ -90,11 +90,10 @@ namespace QuickMedia { if(body_items.empty()) return PluginResult::OK; - std::string url = "https://api.mangadex.org/cover?"; + std::string url = "https://api.mangadex.org/cover?limit=100&order[updatedAt]=desc"; for(size_t i = 0; i < body_items.size(); ++i) { - if(i > 0) - url += "&"; - url += "manga[]=" + body_items[i]->url; + if(!body_items[i]->thumbnail_url.empty()) + url += "&ids[]=" + body_items[i]->thumbnail_url; } Json::Value json_root; @@ -143,6 +142,27 @@ namespace QuickMedia { return PluginResult::OK; } + + static std::string relationships_get_cover_art(const Json::Value &relationships_json) { + std::string result; + if(!relationships_json.isArray()) + return result; + + for(const Json::Value &relationship_json : relationships_json) { + if(!relationship_json.isObject()) + continue; + + const Json::Value &id_json = relationship_json["id"]; + const Json::Value &relationship_type_json = relationship_json["type"]; + if(!id_json.isString() || !relationship_type_json.isString() || strcmp(relationship_type_json.asCString(), "cover_art") != 0) + continue; + + result = id_json.asString(); + break; + } + + return result; + } SearchResult MangadexSearchPage::search(const std::string &str, int page, BodyItems &result_items) { std::string url = "https://api.mangadex.org/manga?title=" + url_param_encode(str) + "&limit=20&offset=" + std::to_string(page * 20); @@ -199,6 +219,8 @@ namespace QuickMedia { body_item->set_description_color(get_current_theme().faded_text_color); } } + + body_item->thumbnail_url = relationships_get_cover_art(result_item_json["relationships"]); result_items.push_back(std::move(body_item)); } -- cgit v1.2.3