diff options
Diffstat (limited to 'src/plugins/Mangadex.cpp')
-rw-r--r-- | src/plugins/Mangadex.cpp | 30 |
1 files changed, 4 insertions, 26 deletions
diff --git a/src/plugins/Mangadex.cpp b/src/plugins/Mangadex.cpp index bf493d3..9808654 100644 --- a/src/plugins/Mangadex.cpp +++ b/src/plugins/Mangadex.cpp @@ -36,21 +36,10 @@ namespace QuickMedia { SearchResult Mangadex::search(const std::string &url, BodyItems &result_items) { std::string manga_id = title_url_extract_manga_id(url); std::string request_url = "https://mangadex.org/api/?id=" + manga_id + "&type=manga"; - std::string server_response; - if(download_to_string(request_url, server_response, {}, use_tor, true) != DownloadResult::OK) - return SearchResult::NET_ERR; - if(server_response.empty()) - return SearchResult::OK; - Json::Value json_root; - Json::CharReaderBuilder json_builder; - std::unique_ptr<Json::CharReader> json_reader(json_builder.newCharReader()); - std::string json_errors; - if(!json_reader->parse(&server_response[0], &server_response[server_response.size()], &json_root, &json_errors)) { - fprintf(stderr, "Mangadex search json error: %s\n", json_errors.c_str()); - return SearchResult::ERR; - } + DownloadResult result = download_json(json_root, request_url, {}, true); + if(result != DownloadResult::OK) return download_result_to_search_result(result); if(!json_root.isObject()) return SearchResult::ERR; @@ -261,21 +250,10 @@ namespace QuickMedia { CommandArg cookie_arg = { "-b", std::move(cookie_filepath) }; std::string manga_id = chapter_url_extract_manga_id(url); std::string request_url = mangadex_url + "/api/?id=" + manga_id + "&server=null&type=chapter"; - std::string server_response; - if(download_to_string(request_url, server_response, {std::move(cookie_arg)}, use_tor, true) != DownloadResult::OK) - return ImageResult::NET_ERR; - - if(server_response.empty()) - return ImageResult::OK; Json::Value json_root; - Json::CharReaderBuilder json_builder; - std::unique_ptr<Json::CharReader> json_reader(json_builder.newCharReader()); - std::string json_errors; - if(!json_reader->parse(&server_response[0], &server_response[server_response.size()], &json_root, &json_errors)) { - fprintf(stderr, "Mangadex image urls json error: %s\n", json_errors.c_str()); - return ImageResult::ERR; - } + DownloadResult result = download_json(json_root, request_url, {std::move(cookie_arg)}, true); + if(result != DownloadResult::OK) return download_result_to_image_result(result); if(!json_root.isObject()) return ImageResult::ERR; |