diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-08-26 05:45:49 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-08-26 05:45:49 +0200 |
commit | 51aa9384f7cf3ba33430ab7cade60ccdfbe06943 (patch) | |
tree | 1f167dd89274d851d8cdb7f7949efedd3bd7fa58 /src | |
parent | 1879c8d8b28bc522bbd5f85851a06c229fb95c2e (diff) |
Mangadex: fix missing thumbnails
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/Mangadex.cpp | 30 |
1 files changed, 26 insertions, 4 deletions
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)); } |