aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/Youtube.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/Youtube.cpp
parent85a1edf8d9c21b830f7ec4a2d42b8e5c1d044845 (diff)
Refactor: move download->json parsing to a one function
Diffstat (limited to 'src/plugins/Youtube.cpp')
-rw-r--r--src/plugins/Youtube.cpp52
1 files changed, 8 insertions, 44 deletions
diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp
index 364f394..7e1fc63 100644
--- a/src/plugins/Youtube.cpp
+++ b/src/plugins/Youtube.cpp
@@ -106,18 +106,9 @@ namespace QuickMedia {
//std::vector<CommandArg> cookies = get_cookies();
//additional_args.insert(additional_args.end(), cookies.begin(), cookies.end());
- std::string website_data;
- if(download_to_string(url + "?pbj=1", website_data, 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(&website_data[0], &website_data[website_data.size()], &json_root, &json_errors)) {
- fprintf(stderr, "Youtube get front page error: %s\n", json_errors.c_str());
- return PluginResult::ERR;
- }
+ DownloadResult result = download_json(json_root, url + "?pbj=1", std::move(additional_args), true);
+ if(result != DownloadResult::OK) return download_result_to_plugin_result(result);
if(!json_root.isArray())
return PluginResult::ERR;
@@ -300,18 +291,9 @@ namespace QuickMedia {
//std::vector<CommandArg> cookies = get_cookies();
//additional_args.insert(additional_args.end(), cookies.begin(), cookies.end());
- std::string website_data;
- if(download_to_string(url + "&pbj=1", website_data, additional_args, use_tor, true) != DownloadResult::OK)
- return SuggestionResult::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(&website_data[0], &website_data[website_data.size()], &json_root, &json_errors)) {
- fprintf(stderr, "Youtube search json error: %s\n", json_errors.c_str());
- return SuggestionResult::ERR;
- }
+ DownloadResult result = download_json(json_root, url + "?pbj=1", std::move(additional_args), true);
+ if(result != DownloadResult::OK) return download_result_to_suggestion_result(result);
if(!json_root.isArray())
return SuggestionResult::ERR;
@@ -380,18 +362,9 @@ namespace QuickMedia {
//std::vector<CommandArg> cookies = get_cookies();
//additional_args.insert(additional_args.end(), cookies.begin(), cookies.end());
- std::string website_data;
- if(download_to_string(next_url, website_data, additional_args, use_tor, true) != DownloadResult::OK)
- return;
-
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(&website_data[0], &website_data[website_data.size()], &json_root, &json_errors)) {
- fprintf(stderr, "Youtube search continuation json error: %s\n", json_errors.c_str());
- return;
- }
+ DownloadResult result = download_json(json_root, next_url, std::move(additional_args), true);
+ if(result != DownloadResult::OK) return;
if(!json_root.isArray())
return;
@@ -521,18 +494,9 @@ namespace QuickMedia {
//std::vector<CommandArg> cookies = get_cookies();
//additional_args.insert(additional_args.end(), cookies.begin(), cookies.end());
- std::string website_data;
- if(download_to_string(modified_url + "&pbj=1", website_data, additional_args, use_tor, true) != DownloadResult::OK)
- return result_items;
-
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(&website_data[0], &website_data[website_data.size()], &json_root, &json_errors)) {
- fprintf(stderr, "Youtube related media error: %s\n", json_errors.c_str());
- return result_items;
- }
+ DownloadResult result = download_json(json_root, modified_url + "&pbj=1", std::move(additional_args), true);
+ if(result != DownloadResult::OK) return result_items;
if(!json_root.isArray())
return result_items;