aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/Manganelo.cpp4
-rw-r--r--src/plugins/Plugin.cpp23
-rw-r--r--src/plugins/Youtube.cpp2
3 files changed, 26 insertions, 3 deletions
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<BodyItem>(text);
+ auto item = std::make_unique<BodyItem>(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<BodyItem>(name_str);
+ auto item = std::make_unique<BodyItem>(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 &param) 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<BodyItem>(title);
+ auto item = std::make_unique<BodyItem>(strip(title));
item->url = std::string("https://www.youtube.com") + href;
result_items->push_back(std::move(item));
}