aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/Plugin.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-12-01 18:05:16 +0100
committerdec05eba <dec05eba@protonmail.com>2019-12-01 18:05:16 +0100
commit6c7adadf6d5c85d5e280e965d4dee1563bf46821 (patch)
treefecdef2d933e0e83e23e0d87bf42139820490bbc /src/plugins/Plugin.cpp
parent129d842030fa993e800009ec0ab170f109e8e899 (diff)
Add 4chan posting
Diffstat (limited to 'src/plugins/Plugin.cpp')
-rw-r--r--src/plugins/Plugin.cpp59
1 files changed, 0 insertions, 59 deletions
diff --git a/src/plugins/Plugin.cpp b/src/plugins/Plugin.cpp
index 7c31292..a9adf15 100644
--- a/src/plugins/Plugin.cpp
+++ b/src/plugins/Plugin.cpp
@@ -1,15 +1,8 @@
#include "../../plugins/Plugin.hpp"
-#include "../../include/Program.h"
#include <sstream>
#include <iomanip>
#include <array>
-static int accumulate_string(char *data, int size, void *userdata) {
- std::string *str = (std::string*)userdata;
- str->append(data, size);
- return 0;
-}
-
namespace QuickMedia {
SearchResult Plugin::search(const std::string &text, BodyItems &result_items) {
(void)text;
@@ -28,44 +21,11 @@ namespace QuickMedia {
return {};
}
- static bool is_whitespace(char c) {
- return c == ' ' || c == '\n' || c == '\t' || c == '\v';
- }
-
- std::string strip(const std::string &str) {
- if(str.empty())
- return str;
-
- int start = 0;
- for(; start < (int)str.size(); ++start) {
- if(!is_whitespace(str[start]))
- break;
- }
-
- int end = str.size() - 1;
- for(; end >= start; --end) {
- if(!is_whitespace(str[end]))
- break;
- }
-
- return str.substr(start, end - start + 1);
- }
-
struct HtmlEscapeSequence {
std::string escape_sequence;
std::string unescaped_str;
};
- void string_replace_all(std::string &str, const std::string &old_str, const std::string &new_str) {
- size_t index = 0;
- while(true) {
- index = str.find(old_str, index);
- if(index == std::string::npos)
- return;
- str.replace(index, old_str.size(), new_str);
- }
- }
-
void html_unescape_sequences(std::string &str) {
const std::array<HtmlEscapeSequence, 6> escape_sequences = {
HtmlEscapeSequence { "&quot;", "\"" },
@@ -97,23 +57,4 @@ namespace QuickMedia {
return result.str();
}
-
- DownloadResult Plugin::download_to_string(const std::string &url, std::string &result, const std::vector<CommandArg> &additional_args) {
- sf::Clock timer;
- std::vector<const char*> args;
- if(use_tor)
- args.push_back("torsocks");
- args.insert(args.end(), { "curl", "-f", "-H", "Accept-Language: en-US,en;q=0.5", "--compressed", "-s", "-L" });
- for(const CommandArg &arg : additional_args) {
- args.push_back(arg.option.c_str());
- args.push_back(arg.value.c_str());
- }
- args.push_back("--");
- args.push_back(url.c_str());
- args.push_back(nullptr);
- if(exec_program(args.data(), accumulate_string, &result) != 0)
- return DownloadResult::NET_ERR;
- fprintf(stderr, "Download duration for %s: %d ms\n", url.c_str(), timer.getElapsedTime().asMilliseconds());
- return DownloadResult::OK;
- }
} \ No newline at end of file