aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/Mangadex.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-10-10 10:43:50 +0200
committerdec05eba <dec05eba@protonmail.com>2020-10-10 10:55:36 +0200
commitda89ec98fb34757f0c46dc8cb2dd87ae78d317ce (patch)
tree653bd81b2125968c706f5552aaeb7d1b7fdc6d04 /src/plugins/Mangadex.cpp
parent85a1edf8d9c21b830f7ec4a2d42b8e5c1d044845 (diff)
Refactor: move download->json parsing to a one function
Diffstat (limited to 'src/plugins/Mangadex.cpp')
-rw-r--r--src/plugins/Mangadex.cpp30
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;