diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-09-13 21:55:09 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-09-13 21:55:09 +0200 |
commit | adcbb9e464bb9033e406008ea9cd209486a292aa (patch) | |
tree | 0f5ebc99adf6ed30bab266e579509f8ea886992e /src | |
parent | b97c4c3ccad3c917e2073329e8d1c7b7351e96aa (diff) |
Fix mangadex search/chapters listing after mangadex api update, combine same author/artist into one
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/Mangadex.cpp | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/src/plugins/Mangadex.cpp b/src/plugins/Mangadex.cpp index 9209828..671e9c7 100644 --- a/src/plugins/Mangadex.cpp +++ b/src/plugins/Mangadex.cpp @@ -113,19 +113,15 @@ namespace QuickMedia { if(!json_root.isObject()) return PluginResult::OK; - const Json::Value &results_json = json_root["results"]; - if(!results_json.isArray()) - return PluginResult::OK; - - for(const Json::Value &result_item_json : results_json) { - if(!result_item_json.isObject()) - continue; + const Json::Value &result_json = json_root["result"]; + if(!result_json.isString() || strcmp(result_json.asCString(), "ok") != 0) + return PluginResult::ERR; - const Json::Value &result_json = result_item_json["result"]; - if(!result_json.isString() || strcmp(result_json.asCString(), "ok") != 0) - continue; + const Json::Value &data_list_json = json_root["data"]; + if(!data_list_json.isArray()) + return PluginResult::ERR; - const Json::Value &data_json = result_item_json["data"]; + for(const Json::Value &data_json : data_list_json) { if(!data_json.isObject()) continue; @@ -187,20 +183,16 @@ namespace QuickMedia { if(!json_root.isObject()) return PluginResult::OK; - const Json::Value &results_json = json_root["results"]; - if(!results_json.isArray()) - return PluginResult::OK; - - const char *prev_chapter = nullptr; - for(const Json::Value &result_item_json : results_json) { - if(!result_item_json.isObject()) - continue; + const Json::Value &result_json = json_root["result"]; + if(!result_json.isString() || strcmp(result_json.asCString(), "ok") != 0) + return PluginResult::ERR; - const Json::Value &result_json = result_item_json["result"]; - if(!result_json.isString() || strcmp(result_json.asCString(), "ok") != 0) - continue; + const Json::Value &data_list_json = json_root["data"]; + if(!data_list_json.isArray()) + return PluginResult::ERR; - const Json::Value &data_json = result_item_json["data"]; + const char *prev_chapter = nullptr; + for(const Json::Value &data_json : data_list_json) { if(!data_json.isObject()) continue; @@ -293,6 +285,7 @@ namespace QuickMedia { Creator creator; creator.name = name_json.asString(); creator.url = id_json.asString(); + creator.creator_type = strcmp(type_json.asCString(), "author") == 0 ? CreatorType::AUTHOR : CreatorType::ARTIST; creators.push_back(std::move(creator)); } } @@ -319,6 +312,17 @@ namespace QuickMedia { return PluginResult::OK; } + static void remove_duplicate_creators(std::vector<Creator> &creators) { + std::sort(creators.begin(), creators.end(), [](const Creator &creator1, const Creator &creator2) { + return creator1.name < creator2.name; + }); + creators.erase( + std::unique(creators.begin(), creators.end(), [](const Creator &creator1, const Creator &creator2) { + return creator1.name == creator2.name; + }), + creators.end()); + } + // TODO: Do requests in parallel PluginResult MangadexSearchPage::submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) { PluginResult result; @@ -337,6 +341,7 @@ namespace QuickMedia { if(result != PluginResult::OK) return result; + remove_duplicate_creators(creators); for(Creator &creator : creators) { result_tabs.push_back(Tab{create_body(), std::make_unique<MangadexCreatorPage>(program, this, std::move(creator)), create_search_bar("Search...", SEARCH_DELAY_FILTER)}); } |