From dc096b888bf7cb1edaad2146ebe0588bc65ba78a Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 25 Aug 2022 23:34:57 +0200 Subject: Mangakatana: fix pages after website update --- src/QuickMedia.cpp | 57 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 7c2283f..f6fe726 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -824,6 +824,33 @@ namespace QuickMedia { .manga_id_handler("/manga/", "/"); } + static std::vector get_javascript_array_string(const std::string &html_source, const std::string &var_name) { + std::vector arr; + size_t sources_start = html_source.find(var_name + "=["); + if(sources_start == std::string::npos) + return arr; + + sources_start += var_name.size() + 1; // just before [ + size_t json_end = find_end_of_json_array(html_source.c_str(), sources_start, html_source.size()); + if(json_end == size_t(-1)) + return arr; + + sources_start += 1; + json_end -= 1; + std::string urls_str = html_source.substr(sources_start, json_end - sources_start); + string_replace_all(urls_str, "'", ""); + + string_split(urls_str, ',', [&arr](const char *str, size_t size) { + std::string url(str, size); + url = strip(url); + if(!url.empty()) + arr.push_back(std::move(url)); + return true; + }); + + return arr; + } + static void add_mangakatana_handlers(MangaGenericSearchPage *manga_generic_search_page) { manga_generic_search_page->search_handler("https://mangakatana.com/page/%p?search=%s&search_by=book_name", 1) .text_handler({ @@ -842,30 +869,12 @@ namespace QuickMedia { .list_chapters_handler("//div[class='chapters']//div[class='chapter']//a[0]", "text", "href", "/manga/") .list_chapters_uploaded_time_handler("//div[class='chapters']//div[class='update_time']", "text", nullptr) .list_page_images_custom_handler([](const std::string &html_source) { - std::vector urls; - size_t sources_start = html_source.find("htnc=["); - if(sources_start == std::string::npos) - return urls; - - sources_start += 5; // just before [ - size_t json_end = find_end_of_json_array(html_source.c_str(), sources_start, html_source.size()); - if(json_end == size_t(-1)) - return urls; - - sources_start += 1; - json_end -= 1; - std::string urls_str = html_source.substr(sources_start, json_end - sources_start); - string_replace_all(urls_str, "'", ""); - - string_split(urls_str, ',', [&urls](const char *str, size_t size) { - std::string url(str, size); - url = strip(url); - if(!url.empty()) - urls.push_back(std::move(url)); - return true; - }); - - return urls; + std::vector urls_ytaw = get_javascript_array_string(html_source, "ytaw"); + std::vector urls_htnc = get_javascript_array_string(html_source, "htnc"); + if(urls_ytaw.size() >= urls_htnc.size()) + return urls_ytaw; + else + return urls_htnc; }) .manga_id_handler("/manga/", nullptr); } -- cgit v1.2.3