diff options
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/Manga.cpp | 7 | ||||
-rw-r--r-- | src/plugins/Mangadex.cpp | 6 | ||||
-rw-r--r-- | src/plugins/Manganelo.cpp | 72 |
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 |