aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-09-15 21:38:24 +0200
committerdec05eba <dec05eba@protonmail.com>2020-09-15 21:38:24 +0200
commit8d661807e363c973dc6a6d7e6015495e7cc3a2ab (patch)
tree4e39bca0226eae8561dc7e3aceccc5e88776533d /src/plugins
parentcef36a1f7c90dba57de53de1fa9fd091e304c833 (diff)
Add manga creators page to navigate to others works by the creators
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/Manga.cpp7
-rw-r--r--src/plugins/Mangadex.cpp6
-rw-r--r--src/plugins/Manganelo.cpp72
3 files changed, 83 insertions, 2 deletions
diff --git a/src/plugins/Manga.cpp b/src/plugins/Manga.cpp
new file mode 100644
index 0000000..6ad11ab
--- /dev/null
+++ b/src/plugins/Manga.cpp
@@ -0,0 +1,7 @@
+#include "../../plugins/Manga.hpp"
+
+namespace QuickMedia {
+ const std::vector<Creator>& Manga::get_creators() const {
+ return creators;
+ }
+} \ No newline at end of file
diff --git a/src/plugins/Mangadex.cpp b/src/plugins/Mangadex.cpp
index 4afa89b..705cbc5 100644
--- a/src/plugins/Mangadex.cpp
+++ b/src/plugins/Mangadex.cpp
@@ -197,6 +197,9 @@ namespace QuickMedia {
}
}, &result_items);
+ if(result != 0)
+ goto cleanup;
+
BodyItemImageContext body_item_image_context;
body_item_image_context.body_items = &result_items;
body_item_image_context.index = 0;
@@ -211,6 +214,9 @@ namespace QuickMedia {
}
}, &body_item_image_context);
+ if(result != 0)
+ goto cleanup;
+
body_item_image_context.index = 0;
result = quickmedia_html_find_nodes_xpath(&html_search, "//div[class='pl-1']",
[](QuickMediaHtmlNode *node, void *userdata) {
diff --git a/src/plugins/Manganelo.cpp b/src/plugins/Manganelo.cpp
index a4c8809..a772601 100644
--- a/src/plugins/Manganelo.cpp
+++ b/src/plugins/Manganelo.cpp
@@ -4,9 +4,16 @@
#include <json/reader.h>
namespace QuickMedia {
+ struct BodyItemImageContext {
+ BodyItems *body_items;
+ size_t index;
+ };
+
SearchResult Manganelo::search(const std::string &url, BodyItems &result_items) {
+ creators.clear();
+
std::string website_data;
- if(download_to_string(url, website_data, {}, use_tor) != DownloadResult::OK)
+ if(download_to_string(url, website_data, {}, use_tor, true) != DownloadResult::OK)
return SearchResult::NET_ERR;
QuickMediaHtmlSearch html_search;
@@ -26,6 +33,19 @@ namespace QuickMedia {
}
}, &result_items);
+ result = quickmedia_html_find_nodes_xpath(&html_search, "//a[class='a-h']",
+ [](QuickMediaHtmlNode *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/")) {
+ Creator creator;
+ creator.name = strip(text);
+ creator.url = href;
+ creators->push_back(std::move(creator));
+ }
+ }, &creators);
+
cleanup:
quickmedia_html_search_deinit(&html_search);
return result == 0 ? SearchResult::OK : SearchResult::ERR;
@@ -112,7 +132,7 @@ namespace QuickMedia {
last_chapter_image_urls.clear();
std::string website_data;
- if(download_to_string(url, website_data, {}, use_tor) != DownloadResult::OK)
+ if(download_to_string(url, website_data, {}, use_tor, true) != DownloadResult::OK)
return ImageResult::NET_ERR;
QuickMediaHtmlSearch html_search;
@@ -191,4 +211,52 @@ namespace QuickMedia {
return false;
}
}
+
+ PluginResult Manganelo::get_creators_manga_list(const std::string &url, BodyItems &result_items) {
+ std::string website_data;
+ if(download_to_string(url, website_data, {}, use_tor, true) != DownloadResult::OK)
+ return PluginResult::NET_ERR;
+
+ QuickMediaHtmlSearch html_search;
+ int result = quickmedia_html_search_init(&html_search, website_data.c_str());
+ 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) {
+ 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 = std::make_unique<BodyItem>(title);
+ body_item->url = href;
+ item_data->push_back(std::move(body_item));
+ }
+ }, &result_items);
+
+ if(result != 0)
+ goto cleanup;
+
+ BodyItemImageContext body_item_image_context;
+ body_item_image_context.body_items = &result_items;
+ 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) {
+ auto *item_data = (BodyItemImageContext*)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;
+ item_data->index++;
+ }
+ }, &body_item_image_context);
+
+ cleanup:
+ quickmedia_html_search_deinit(&html_search);
+ if(result != 0) {
+ result_items.clear();
+ return PluginResult::ERR;
+ }
+ return PluginResult::OK;
+ }
} \ No newline at end of file