aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/Manganelo.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-07-03 16:23:36 +0200
committerdec05eba <dec05eba@protonmail.com>2021-07-03 18:34:37 +0200
commit611d22bf269672ba56f98e12eb6b2a40efdaa5b9 (patch)
tree5dfd3e98fd08fa7cb6cb82c565b538cc891b6b98 /src/plugins/Manganelo.cpp
parent496f71413df2468a9d3329355ffef08280219808 (diff)
Remove dependency on tidy, fix ph, support all 4chan markup
Go back to previous page when failing to fetch number of pages
Diffstat (limited to 'src/plugins/Manganelo.cpp')
-rw-r--r--src/plugins/Manganelo.cpp83
1 files changed, 46 insertions, 37 deletions
diff --git a/src/plugins/Manganelo.cpp b/src/plugins/Manganelo.cpp
index 094d096..e0517dd 100644
--- a/src/plugins/Manganelo.cpp
+++ b/src/plugins/Manganelo.cpp
@@ -1,11 +1,14 @@
#include "../../plugins/Manganelo.hpp"
#include "../../include/Notification.hpp"
-#include "../../include/StringUtils.hpp"
#include "../../include/NetUtils.hpp"
#include "../../include/Theme.hpp"
#include <quickmedia/HtmlSearch.h>
namespace QuickMedia {
+ static bool string_view_contains(const QuickMediaStringView str, const char *sub) {
+ return memmem(str.data, str.size, sub, strlen(sub));
+ }
+
// Returns true if modified
static bool remove_html_span(std::string &str) {
size_t open_tag_start = str.find("<span");
@@ -35,20 +38,21 @@ namespace QuickMedia {
return PluginResult::NET_ERR;
QuickMediaHtmlSearch html_search;
- int result = quickmedia_html_search_init(&html_search, website_data.c_str());
+ int result = quickmedia_html_search_init(&html_search, website_data.c_str(), website_data.size());
if(result != 0)
goto cleanup;
result = quickmedia_html_find_nodes_xpath(&html_search, "//ul[class='row-content-chapter']//a",
- [](QuickMediaHtmlNode *node, void *userdata) {
+ [](QuickMediaMatchNode *node, void *userdata) {
auto *item_data = (BodyItems*)userdata;
- 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 = BodyItem::create(strip(text));
- item->url = strip(href);
+ QuickMediaStringView href = quickmedia_html_node_get_attribute_value(node, "href");
+ QuickMediaStringView text = quickmedia_html_node_get_text(node);
+ if(href.data && text.data) {
+ auto item = BodyItem::create(std::string(text.data, text.size));
+ item->url.assign(href.data, href.size);
item_data->push_back(std::move(item));
}
+ return 0;
}, &chapters_items);
BodyItemContext body_item_context;
@@ -56,29 +60,31 @@ namespace QuickMedia {
body_item_context.index = 0;
quickmedia_html_find_nodes_xpath(&html_search, "//ul[class='row-content-chapter']//span",
- [](QuickMediaHtmlNode *node, void *userdata) {
+ [](QuickMediaMatchNode *node, void *userdata) {
auto *item_data = (BodyItemContext*)userdata;
- const char *class_attr = quickmedia_html_node_get_attribute_value(node, "class");
- const char *text = quickmedia_html_node_get_text(node);
- if(text && class_attr && strstr(class_attr, "chapter-time") && item_data->index < item_data->body_items->size()) {
- std::string uploaded_date = strip(text);
- (*item_data->body_items)[item_data->index]->set_description("Uploaded: " + uploaded_date);
+ QuickMediaStringView class_attr = quickmedia_html_node_get_attribute_value(node, "class");
+ QuickMediaStringView text = quickmedia_html_node_get_text(node);
+ if(text.data && class_attr.data && string_view_contains(class_attr, "chapter-time") && item_data->index < item_data->body_items->size()) {
+ std::string uploaded_date(text.data, text.size);
+ (*item_data->body_items)[item_data->index]->set_description("Uploaded: " + std::move(uploaded_date));
(*item_data->body_items)[item_data->index]->set_description_color(get_current_theme().faded_text_color);
item_data->index++;
}
+ return 0;
}, &body_item_context);
quickmedia_html_find_nodes_xpath(&html_search, "//a[class='a-h']",
- [](QuickMediaHtmlNode *node, void *userdata) {
+ [](QuickMediaMatchNode *node, void *userdata) {
std::vector<Creator> *creators = (std::vector<Creator>*)userdata;
- const char *href = quickmedia_html_node_get_attribute_value(node, "href");
- const char *text = quickmedia_html_node_get_text(node);
- if(href && text && strstr(href, "/author/story/")) {
+ QuickMediaStringView href = quickmedia_html_node_get_attribute_value(node, "href");
+ QuickMediaStringView text = quickmedia_html_node_get_text(node);
+ if(href.data && text.data && string_view_contains(href, "/author/story/")) {
Creator creator;
- creator.name = strip(text);
- creator.url = strip(href);
+ creator.name.assign(text.data, text.size);
+ creator.url.assign(href.data, href.size);
creators->push_back(std::move(creator));
}
+ return 0;
}, &creators);
cleanup:
@@ -124,7 +130,7 @@ namespace QuickMedia {
if(name.isString() && name.asCString()[0] != '\0' && nameunsigned.isString() && nameunsigned.asCString()[0] != '\0') {
std::string name_str = name.asString();
while(remove_html_span(name_str)) {}
- auto item = BodyItem::create(strip(name_str));
+ auto item = BodyItem::create(name_str);
item->url = "https://manganelo.com/manga/" + url_param_encode(nameunsigned.asString());
if(lastchapter.isString() && lastchapter.asCString()[0] != '\0') {
item->set_description("Latest chapter: " + lastchapter.asString());
@@ -192,20 +198,21 @@ namespace QuickMedia {
return PluginResult::NET_ERR;
QuickMediaHtmlSearch html_search;
- int result = quickmedia_html_search_init(&html_search, website_data.c_str());
+ int result = quickmedia_html_search_init(&html_search, website_data.c_str(), website_data.size());
if(result != 0)
goto cleanup;
result = quickmedia_html_find_nodes_xpath(&html_search, "//div[class='search-story-item']//a[class='item-img']",
- [](QuickMediaHtmlNode *node, void *userdata) {
+ [](QuickMediaMatchNode *node, void *userdata) {
auto *item_data = (BodyItems*)userdata;
- const char *href = quickmedia_html_node_get_attribute_value(node, "href");
- const char *title = quickmedia_html_node_get_attribute_value(node, "title");
- if(href && title && strstr(href, "/manga/")) {
- auto body_item = BodyItem::create(strip(title));
- body_item->url = strip(href);
+ QuickMediaStringView href = quickmedia_html_node_get_attribute_value(node, "href");
+ QuickMediaStringView title = quickmedia_html_node_get_attribute_value(node, "title");
+ if(href.data && title.data && string_view_contains(href, "/manga/")) {
+ auto body_item = BodyItem::create(std::string(title.data, title.size));
+ body_item->url.assign(href.data, href.size);
item_data->push_back(std::move(body_item));
}
+ return 0;
}, &result_items);
if(result != 0)
@@ -216,13 +223,14 @@ namespace QuickMedia {
body_item_image_context.index = 0;
result = quickmedia_html_find_nodes_xpath(&html_search, "//div[class='search-story-item']//a[class='item-img']//img",
- [](QuickMediaHtmlNode *node, void *userdata) {
+ [](QuickMediaMatchNode *node, void *userdata) {
auto *item_data = (BodyItemContext*)userdata;
- const char *src = quickmedia_html_node_get_attribute_value(node, "src");
- if(src && item_data->index < item_data->body_items->size()) {
- (*item_data->body_items)[item_data->index]->thumbnail_url = src;
+ QuickMediaStringView src = quickmedia_html_node_get_attribute_value(node, "src");
+ if(src.data && item_data->index < item_data->body_items->size()) {
+ (*item_data->body_items)[item_data->index]->thumbnail_url.assign(src.data, src.size);
item_data->index++;
}
+ return 0;
}, &body_item_image_context);
cleanup:
@@ -261,18 +269,19 @@ namespace QuickMedia {
return ImageResult::NET_ERR;
QuickMediaHtmlSearch html_search;
- int result = quickmedia_html_search_init(&html_search, website_data.c_str());
+ int result = quickmedia_html_search_init(&html_search, website_data.c_str(), website_data.size());
if(result != 0)
goto cleanup;
result = quickmedia_html_find_nodes_xpath(&html_search, "//div[class='container-chapter-reader']/img",
- [](QuickMediaHtmlNode *node, void *userdata) {
+ [](QuickMediaMatchNode *node, void *userdata) {
auto *urls = (std::vector<std::string>*)userdata;
- const char *src = quickmedia_html_node_get_attribute_value(node, "src");
- if(src) {
- std::string image_url = strip(src);
+ QuickMediaStringView src = quickmedia_html_node_get_attribute_value(node, "src");
+ if(src.data) {
+ std::string image_url(src.data, src.size);
urls->push_back(std::move(image_url));
}
+ return 0;
}, &chapter_image_urls);
cleanup: