From 0fda98b233ae0f44b1f0a8691958087619b243e1 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 12 Oct 2019 08:10:32 +0200 Subject: Start on 4chan, go to previous/next chapter when reaching beginning/end --- src/plugins/Plugin.cpp | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'src/plugins/Plugin.cpp') diff --git a/src/plugins/Plugin.cpp b/src/plugins/Plugin.cpp index 79c6403..c56ff67 100644 --- a/src/plugins/Plugin.cpp +++ b/src/plugins/Plugin.cpp @@ -2,6 +2,7 @@ #include "../../include/Program.h" #include #include +#include static int accumulate_string(char *data, int size, void *userdata) { std::string *str = (std::string*)userdata; @@ -28,7 +29,8 @@ namespace QuickMedia { } DownloadResult download_to_string(const std::string &url, std::string &result, const std::vector &additional_args) { - std::vector args = { "curl", "-H", "Accept-Language: en-US,en;q=0.5", "--compressed", "-s", "-L" }; + sf::Clock timer; + std::vector args = { "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()); @@ -38,6 +40,7 @@ namespace QuickMedia { 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; } @@ -64,6 +67,35 @@ namespace QuickMedia { 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 escape_sequences = { + HtmlEscapeSequence { """, "\"" }, + HtmlEscapeSequence { "'", "'" }, + HtmlEscapeSequence { "<", "<" }, + HtmlEscapeSequence { ">", ">" }, + HtmlEscapeSequence { "&", "&" } // This should be last, to not accidentally replace a new sequence caused by replacing this + }; + + for(const HtmlEscapeSequence &escape_sequence : escape_sequences) { + string_replace_all(str, escape_sequence.escape_sequence, escape_sequence.unescaped_str); + } + } + std::string Plugin::url_param_encode(const std::string ¶m) const { std::ostringstream result; result.fill('0'); -- cgit v1.2.3