aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/Fourchan.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/Fourchan.cpp')
-rw-r--r--src/plugins/Fourchan.cpp38
1 files changed, 6 insertions, 32 deletions
diff --git a/src/plugins/Fourchan.cpp b/src/plugins/Fourchan.cpp
index 757a0e1..1cecc2b 100644
--- a/src/plugins/Fourchan.cpp
+++ b/src/plugins/Fourchan.cpp
@@ -211,18 +211,9 @@ namespace QuickMedia {
}
PluginResult Fourchan::get_threads_internal(const std::string &url, BodyItems &result_items) {
- std::string server_response;
- if(download_to_string(fourchan_url + url + "/catalog.json", server_response, {}, use_tor) != DownloadResult::OK)
- return PluginResult::NET_ERR;
-
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.data(), server_response.data() + server_response.size(), &json_root, &json_errors)) {
- fprintf(stderr, "4chan catalog json error: %s\n", json_errors.c_str());
- return PluginResult::ERR;
- }
+ DownloadResult result = download_json(json_root, fourchan_url + url + "/catalog.json", {}, true);
+ if(result != DownloadResult::OK) return download_result_to_plugin_result(result);
if(json_root.isArray()) {
for(const Json::Value &page_data : json_root) {
@@ -402,18 +393,10 @@ namespace QuickMedia {
// TODO: Merge with get_threads_internal
PluginResult Fourchan::get_thread_comments(const std::string &list_url, const std::string &url, BodyItems &result_items) {
cached_media_urls.clear();
- std::string server_response;
- if(download_to_string(fourchan_url + list_url + "/thread/" + url + ".json", server_response, {}, use_tor) != DownloadResult::OK)
- return PluginResult::NET_ERR;
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.data(), server_response.data() + server_response.size(), &json_root, &json_errors)) {
- fprintf(stderr, "4chan thread json error: %s\n", json_errors.c_str());
- return PluginResult::ERR;
- }
+ DownloadResult result = download_json(json_root, fourchan_url + list_url + "/thread/" + url + ".json", {}, true);
+ if(result != DownloadResult::OK) return download_result_to_plugin_result(result);
if(!json_root.isObject())
return PluginResult::ERR;
@@ -618,18 +601,9 @@ namespace QuickMedia {
CommandArg{"-c", cookies_filepath.data}
};
- std::string response;
- if(download_to_string("https://sys.4chan.org/auth", response, std::move(additional_args), use_tor, true) != DownloadResult::OK)
- return PluginResult::NET_ERR;
-
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(&response[0], &response[response.size()], &json_root, &json_errors) || !json_root.isObject()) {
- fprintf(stderr, "Youtube get front page error: %s\n", json_errors.c_str());
- return PluginResult::ERR;
- }
+ DownloadResult result = download_json(json_root, "https://sys.4chan.org/auth", std::move(additional_args), true);
+ if(result != DownloadResult::OK) return download_result_to_plugin_result(result);
if(!json_root.isObject())
return PluginResult::ERR;