diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-04-16 20:09:02 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-04-16 21:08:18 +0200 |
commit | 88d3dbbd12d17056323f40effe00ce8ab8180691 (patch) | |
tree | 7bf1afc1b81b08124ed6f5d7eb2d3a0f89082c4e /plugins | |
parent | ba4e62d55156f9b94b569b56b6382bbcf94b7d86 (diff) |
Add mangakatana
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/MangaGeneric.hpp | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/plugins/MangaGeneric.hpp b/plugins/MangaGeneric.hpp index 7d63622..d58672a 100644 --- a/plugins/MangaGeneric.hpp +++ b/plugins/MangaGeneric.hpp @@ -5,8 +5,7 @@ namespace QuickMedia { struct SearchQuery { - const char *search_prefix = nullptr; - const char *page_prefix = nullptr; + const char *search_template = nullptr; int page_start = 0; }; @@ -42,13 +41,9 @@ namespace QuickMedia { ListPageImagesQueryPost post_handler = nullptr; }; - // Return the actual number of pages - using ListPagePaginationPagesPost = std::function<int(int num_pages)>; struct ListPagePaginationQuery { const char *pages_html_query = nullptr; const char *pages_field_name = nullptr; - const char *pages_field_contains = nullptr; - ListPagePaginationPagesPost pages_post_handler = nullptr; const char *image_html_query = nullptr; const char *image_field_name = nullptr; @@ -59,15 +54,23 @@ namespace QuickMedia { const char *next_page_field_contains = nullptr; }; + // Return the image sources + using ListPageCustomHandler = std::function<std::vector<std::string>(const std::string &html_source)>; + struct ListPageCustomQuery { + ListPageCustomHandler handler; + }; + enum class ListPageQueryType { IMAGES, - PAGINATION + PAGINATION, + CUSTOM }; struct ListPageQuery { ListPageQueryType type = ListPageQueryType::IMAGES; ListPageImagesQuery images_query; ListPagePaginationQuery pagination_query; + ListPageCustomQuery custom_query; }; struct MangaIdExtractor { @@ -77,7 +80,7 @@ namespace QuickMedia { class MangaGenericSearchPage : public Page { public: - MangaGenericSearchPage(Program *program, const char *service_name, const char *website_url); + MangaGenericSearchPage(Program *program, const char *service_name, const char *website_url, bool fail_on_http_error = true); const char* get_title() const override { return "All"; } bool search_is_filter() override { return false; } SearchResult search(const std::string &str, BodyItems &result_items) override; @@ -85,12 +88,10 @@ namespace QuickMedia { PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override; sf::Vector2i get_thumbnail_max_size() override { return sf::Vector2i(101, 141); }; - // Add a %s where the query or page number should be inserted into |search_prefix| and |page_prefix|, for example: - // search_prefix: example.com/search?q=%s - // page_prefix: &page=%s - // |page_start| is the first page, so the result page is |page_start| + |page| where page is the current page we are navigating on. + // Add a %s where the search query should be inserted into |search_template| and add a %p where the page number should be inserted, for example: + // example.com/search?q=%s&page=%p // This is required. - MangaGenericSearchPage& search_handler(const char *search_prefix, const char *page_prefix, int page_start); + MangaGenericSearchPage& search_handler(const char *search_template, int page_start); // If |url_contains| is null, then any matching query is added. If |title_field| is "text", then the inner text is used. // This is required. MangaGenericSearchPage& text_handler(const char *html_query, const char *title_field, const char *url_field, const char *url_contains); @@ -106,16 +107,20 @@ namespace QuickMedia { MangaGenericSearchPage& list_chapters_uploaded_time_handler(const char *html_query, const char *field_name, const char *field_contains); // If |field_contains| is null, then any matching query is added. If |field_name| is "text", then the inner text is used. - // This or |list_page_images_pagination_handler| is required. + // This or |list_page_images_pagination_handler| or |list_page_images_custom_handler| is required. MangaGenericSearchPage& list_page_images_handler(const char *html_query, const char *field_name, const char *field_contains, ListPageImagesQueryPost post_handler = nullptr); - // If |pages_field_contains| or |image_field_contains| is null, then any matching query is added. If |pages_field_name| or |image_field_name| is "text", then the inner text is used. - // This or |list_page_images_handler| is required. + // If |image_field_contains| is null, then any matching query is added. If |pages_field_name| or |image_field_name| is "text", then the inner text is used. + // The last matching pages html query item is chosen as the number of pages. + // This or |list_page_images_handler| or |list_page_images_custom_handler| is required. MangaGenericSearchPage& list_page_images_pagination_handler( - const char *pages_html_query, const char *pages_field_name, const char *pages_field_contains, ListPagePaginationPagesPost pages_post_handler, + const char *pages_html_query, const char *pages_field_name, const char *image_html_query, const char *image_field_name, const char *image_field_contains, const char *next_page_html_query, const char *next_page_field_name, const char *next_page_field_contains); + // This or |list_page_images_handler| or |list_page_images_pagination_handler| is required. + MangaGenericSearchPage& list_page_images_custom_handler(ListPageCustomHandler handler); + // For example: mangasite.com/manga/204353&f=23 // /manga/ here would be the |prefix| and & would be |end|. |end| is optional. // The goal is to extract 204353 from the manga chapter page url. @@ -123,6 +128,7 @@ namespace QuickMedia { private: const char *service_name; std::string website_url; + bool fail_on_http_error; SearchQuery search_query; TextQuery text_query; ThumbnailQuery thumbnail_query; @@ -133,8 +139,8 @@ namespace QuickMedia { class MangaGenericChaptersPage : public MangaChaptersPage { public: - MangaGenericChaptersPage(Program *program, std::string manga_name, std::string manga_url, const MangaIdExtractor &manga_id_extractor, const char *service_name, const std::string &website_url, const ListPageQuery *list_page_query) : - MangaChaptersPage(program, std::move(manga_name), std::move(manga_url)), manga_id_extractor(manga_id_extractor), service_name(service_name), website_url(website_url), list_page_query(list_page_query) {} + MangaGenericChaptersPage(Program *program, std::string manga_name, std::string manga_url, const MangaIdExtractor &manga_id_extractor, const char *service_name, const std::string &website_url, const ListPageQuery *list_page_query, bool fail_on_http_error) : + MangaChaptersPage(program, std::move(manga_name), std::move(manga_url)), manga_id_extractor(manga_id_extractor), service_name(service_name), website_url(website_url), list_page_query(list_page_query), fail_on_http_error(fail_on_http_error) {} PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override; protected: bool extract_id_from_url(const std::string &url, std::string &manga_id) const override; @@ -144,12 +150,13 @@ namespace QuickMedia { const char *service_name; std::string website_url; const ListPageQuery *list_page_query; + bool fail_on_http_error; }; class MangaGenericImagesPage : public MangaImagesPage { public: - MangaGenericImagesPage(Program *program, std::string manga_name, std::string chapter_name, std::string url, const char *service_name, const std::string &website_url, const ListPageQuery *list_page_query) : - MangaImagesPage(program, std::move(manga_name), std::move(chapter_name), std::move(url)), service_name(service_name), website_url(website_url), list_page_query(list_page_query) {} + MangaGenericImagesPage(Program *program, std::string manga_name, std::string chapter_name, std::string url, const char *service_name, const std::string &website_url, const ListPageQuery *list_page_query, bool fail_on_http_error) : + MangaImagesPage(program, std::move(manga_name), std::move(chapter_name), std::move(url)), service_name(service_name), website_url(website_url), list_page_query(list_page_query), fail_on_http_error(fail_on_http_error) {} ImageResult get_number_of_images(int &num_images) override; ImageResult for_each_page_in_chapter(PageCallback callback) override; const char* get_service_name() const override { return service_name; } @@ -159,7 +166,7 @@ namespace QuickMedia { const char *service_name; std::string website_url; const ListPageQuery *list_page_query; - std::string prev_chapter_url; + bool fail_on_http_error; std::string current_image_url; std::string next_page_url; }; |