From 58481b46a2c64fda4f506e15ee94dd97f527d552 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 6 Aug 2019 03:12:16 +0200 Subject: Save and show progress in manga and return to last page" --- src/plugins/Manganelo.cpp | 4 ++-- src/plugins/Plugin.cpp | 23 +++++++++++++++++++++++ src/plugins/Youtube.cpp | 2 +- 3 files changed, 26 insertions(+), 3 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/Manganelo.cpp b/src/plugins/Manganelo.cpp index e8d24dc..1989a37 100644 --- a/src/plugins/Manganelo.cpp +++ b/src/plugins/Manganelo.cpp @@ -21,7 +21,7 @@ namespace QuickMedia { const char *href = quickmedia_html_node_get_attribute_value(node, "href"); const char *text = quickmedia_html_node_get_text(node); if(href && text) { - auto item = std::make_unique(text); + auto item = std::make_unique(strip(text)); item->url = href; item_data->push_back(std::move(item)); } @@ -83,7 +83,7 @@ namespace QuickMedia { std::string name_str = name.asString(); while(remove_html_span(name_str)) {} if(name_str != text) { - auto item = std::make_unique(name_str); + auto item = std::make_unique(strip(name_str)); item->url = "https://manganelo.com/manga/" + url_param_encode(nameunsigned.asString()); Json::Value image = child.get("image", ""); if(image.isString() && image.asCString()[0] != '\0') diff --git a/src/plugins/Plugin.cpp b/src/plugins/Plugin.cpp index d87ac34..2367cb3 100644 --- a/src/plugins/Plugin.cpp +++ b/src/plugins/Plugin.cpp @@ -33,6 +33,29 @@ namespace QuickMedia { return DownloadResult::OK; } + 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); + } + std::string Plugin::url_param_encode(const std::string ¶m) const { std::ostringstream result; result.fill('0'); diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp index 6cc4ac6..4ee3933 100644 --- a/src/plugins/Youtube.cpp +++ b/src/plugins/Youtube.cpp @@ -29,7 +29,7 @@ namespace QuickMedia { const char *title = quickmedia_html_node_get_attribute_value(node, "title"); // Checking for watch?v helps skipping ads if(href && title && begins_with(href, "/watch?v=")) { - auto item = std::make_unique(title); + auto item = std::make_unique(strip(title)); item->url = std::string("https://www.youtube.com") + href; result_items->push_back(std::move(item)); } -- cgit v1.2.3