diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-08-03 01:52:27 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2019-08-03 01:52:30 +0200 |
commit | 117eb25e36ac3b1e1ba18cc9f1e177016c076f34 (patch) | |
tree | 04bd7fe4662af4c8b5d352098430c489082e71aa /src/Plugin.cpp | |
parent | 65cf7681a04f2511db8c7829e9828b53a6676c88 (diff) |
Add search suggestions for youtube & manganelo
Diffstat (limited to 'src/Plugin.cpp')
-rw-r--r-- | src/Plugin.cpp | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/src/Plugin.cpp b/src/Plugin.cpp index d2fe925..382ebbf 100644 --- a/src/Plugin.cpp +++ b/src/Plugin.cpp @@ -1,5 +1,7 @@ #include "../plugins/Plugin.hpp" #include "../include/Program.h" +#include <sstream> +#include <iomanip> static int accumulate_string(char *data, int size, void *userdata) { std::string *str = (std::string*)userdata; @@ -8,10 +10,38 @@ static int accumulate_string(char *data, int size, void *userdata) { } namespace QuickMedia { - DownloadResult Plugin::download_to_string(const std::string &url, std::string &result) { - const char *args[] = { "curl", "-H", "Accept-Language: en-US,en;q=0.5", "--compressed", "-s", "-L", url.c_str(), nullptr }; - if(exec_program(args, accumulate_string, &result) != 0) + SuggestionResult Plugin::update_search_suggestions(const std::string &text, std::vector<std::unique_ptr<BodyItem>> &result_items) { + (void)text; + (void)result_items; + return SuggestionResult::OK; + } + + DownloadResult Plugin::download_to_string(const std::string &url, std::string &result, const std::vector<CommandArg> &additional_args) { + std::vector<const char*> args = { "curl", "-H", "Accept-Language: en-US,en;q=0.5", "--compressed", "-s", "-L", url.c_str() }; + for(const CommandArg &arg : additional_args) { + args.push_back(arg.option.c_str()); + args.push_back(arg.value.c_str()); + } + args.push_back(nullptr); + if(exec_program(args.data(), accumulate_string, &result) != 0) return DownloadResult::NET_ERR; return DownloadResult::OK; } + + std::string Plugin::url_param_encode(const std::string ¶m) const { + std::ostringstream result; + result.fill('0'); + result << std::hex; + + for(char c : param) { + if(isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') { + result << c; + } else { + result << std::uppercase; + result << "%" << std::setw(2) << (int)(unsigned char)(c); + } + } + + return result.str(); + } }
\ No newline at end of file |