diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-09-13 17:58:35 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-09-13 17:58:35 +0200 |
commit | a73eb41773d3f70867358bbef26563ca431b0908 (patch) | |
tree | f12c769564ae143cdbac25ea8c18ee2dcfc625a9 | |
parent | 9d4879215bb7b3b89122a930f86248cc405536a1 (diff) |
Add thumbnails to mangatown search results
-rw-r--r-- | plugins/Mangatown.hpp | 4 | ||||
-rw-r--r-- | src/plugins/Mangadex.cpp | 8 | ||||
-rw-r--r-- | src/plugins/Mangatown.cpp | 52 |
3 files changed, 57 insertions, 7 deletions
diff --git a/plugins/Mangatown.hpp b/plugins/Mangatown.hpp index bfb1f6a..2a22ccd 100644 --- a/plugins/Mangatown.hpp +++ b/plugins/Mangatown.hpp @@ -11,9 +11,9 @@ namespace QuickMedia { SearchResult search(const std::string &url, BodyItems &result_items) override; SuggestionResult update_search_suggestions(const std::string &text, BodyItems &result_items) override; ImageResult get_number_of_images(const std::string &url, int &num_images) override; - bool search_suggestions_has_thumbnails() const override { return false; } + bool search_suggestions_has_thumbnails() const override { return true; } bool search_results_has_thumbnails() const override { return false; } - int get_search_delay() const override { return 150; } + int get_search_delay() const override { return 200; } Page get_page_after_search() const override { return Page::EPISODE_LIST; } ImageResult for_each_page_in_chapter(const std::string &chapter_url, PageCallback callback) override; diff --git a/src/plugins/Mangadex.cpp b/src/plugins/Mangadex.cpp index 7688355..10f689f 100644 --- a/src/plugins/Mangadex.cpp +++ b/src/plugins/Mangadex.cpp @@ -205,11 +205,9 @@ namespace QuickMedia { [](QuickMediaHtmlNode *node, void *userdata) { auto *item_data = (BodyItemImageContext*)userdata; const char *src = quickmedia_html_node_get_attribute_value(node, "src"); - if(src && strncmp(src, "/images/manga/", 14) == 0) { - if(item_data->index < item_data->body_items->size()) { - (*item_data->body_items)[item_data->index]->thumbnail_url = mangadex_url + src; - item_data->index++; - } + if(src && strncmp(src, "/images/manga/", 14) == 0 && item_data->index < item_data->body_items->size()) { + (*item_data->body_items)[item_data->index]->thumbnail_url = mangadex_url + src; + item_data->index++; } }, &body_item_image_context); diff --git a/src/plugins/Mangatown.cpp b/src/plugins/Mangatown.cpp index cb3217b..67f4c29 100644 --- a/src/plugins/Mangatown.cpp +++ b/src/plugins/Mangatown.cpp @@ -40,7 +40,13 @@ namespace QuickMedia { return result == 0 ? SearchResult::OK : SearchResult::ERR; } + struct BodyItemImageContext { + BodyItems *body_items; + size_t index; + }; + SuggestionResult Mangatown::update_search_suggestions(const std::string &text, BodyItems &result_items) { +#if 0 std::string url = "https://www.mangatown.com/ajax/search/?query="; url += url_param_encode(text); @@ -95,6 +101,52 @@ namespace QuickMedia { } return SuggestionResult::OK; +#else + std::string url = "https://www.mangatown.com/search?name="; + url += url_param_encode(text); + + std::string website_data; + if(download_to_string(url, website_data, {}, use_tor, true) != DownloadResult::OK) + return SuggestionResult::NET_ERR; + + if(website_data.empty()) + return SuggestionResult::OK; + + 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, "//p[class='title']/a", + [](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 && strncmp(href, "/manga/", 7) == 0) { + auto item = std::make_unique<BodyItem>(strip(title)); + item->url = mangatown_url + href; + item_data->push_back(std::move(item)); + } + }, &result_items); + + 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, "//a[class='manga_cover']/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); + return SuggestionResult::OK; +#endif } static bool is_number_with_zero_fill(const char *str) { |