From e65d0b4effdbbcc9393c58075c010f59231fd45e Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 13 Feb 2022 19:19:31 +0100 Subject: Make manga images pages less error prone --- src/plugins/LocalManga.cpp | 30 ++++++++++-------------------- src/plugins/MangaGeneric.cpp | 20 ++------------------ src/plugins/Mangadex.cpp | 30 ++++++++++-------------------- src/plugins/Manganelo.cpp | 30 ++++++++++-------------------- 4 files changed, 32 insertions(+), 78 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/LocalManga.cpp b/src/plugins/LocalManga.cpp index ed0f1b2..34a2983 100644 --- a/src/plugins/LocalManga.cpp +++ b/src/plugins/LocalManga.cpp @@ -490,27 +490,8 @@ namespace QuickMedia { return true; } - ImageResult LocalMangaImagesPage::get_number_of_images(int &num_images) { + ImageResult LocalMangaImagesPage::update_image_urls(int &num_images) { num_images = 0; - ImageResult image_result = get_image_urls_for_chapter(url); - if(image_result != ImageResult::OK) return image_result; - num_images = chapter_image_urls.size(); - return ImageResult::OK; - } - - ImageResult LocalMangaImagesPage::for_each_page_in_chapter(PageCallback callback) { - ImageResult image_result = get_image_urls_for_chapter(url); - if(image_result != ImageResult::OK) return image_result; - for(const std::string &url : chapter_image_urls) { - if(!callback(url)) - break; - } - return ImageResult::OK; - } - - ImageResult LocalMangaImagesPage::get_image_urls_for_chapter(const std::string &url) { - if(!chapter_image_urls.empty()) - return ImageResult::OK; Path chapter_url = Path(get_config().local_manga_directory).join(manga_name).join(url); std::vector pages = get_images_in_manga(chapter_url); @@ -521,6 +502,15 @@ namespace QuickMedia { chapter_image_urls.push_back(local_manga_page.path.data); } + num_images = chapter_image_urls.size(); + return ImageResult::OK; + } + + ImageResult LocalMangaImagesPage::for_each_page_in_chapter(PageCallback callback) { + for(const std::string &url : chapter_image_urls) { + if(!callback(url)) + break; + } return ImageResult::OK; } } \ No newline at end of file diff --git a/src/plugins/MangaGeneric.cpp b/src/plugins/MangaGeneric.cpp index 609dab9..47fbf08 100644 --- a/src/plugins/MangaGeneric.cpp +++ b/src/plugins/MangaGeneric.cpp @@ -423,7 +423,7 @@ namespace QuickMedia { return true; } - ImageResult MangaGenericImagesPage::get_number_of_images(int &num_images) { + ImageResult MangaGenericImagesPage::update_image_urls(int &num_images) { num_images = 0; switch(list_page_query->type) { case ListPageQueryType::IMAGES: { @@ -442,11 +442,6 @@ namespace QuickMedia { return ImageResult::ERR; } - if(chapter_num_pages != -1) { - num_images = chapter_num_pages; - return ImageResult::OK; - } - current_image_url.clear(); next_page_url.clear(); @@ -535,8 +530,6 @@ namespace QuickMedia { ImageResult MangaGenericImagesPage::for_each_page_in_chapter(PageCallback callback) { switch(list_page_query->type) { case ListPageQueryType::IMAGES: { - ImageResult result = get_page_image_urls(); - if(result != ImageResult::OK) return result; for(const std::string &url : chapter_image_urls) { if(!callback(url)) break; @@ -552,14 +545,10 @@ namespace QuickMedia { return ImageResult::ERR; } - int num_images = 0; - ImageResult result = get_number_of_images(num_images); - if(result != ImageResult::OK) return result; - if(!callback(current_image_url)) return ImageResult::OK; - for(int i = 0; i < num_images; ++i) { + for(int i = 0; i < chapter_num_pages; ++i) { std::string full_url = url + next_page_url; current_image_url.clear(); next_page_url.clear(); @@ -609,8 +598,6 @@ namespace QuickMedia { return ImageResult::OK; } case ListPageQueryType::CUSTOM: { - ImageResult result = get_page_image_urls(); - if(result != ImageResult::OK) return result; for(const std::string &url : chapter_image_urls) { if(!callback(url)) break; @@ -622,9 +609,6 @@ namespace QuickMedia { } ImageResult MangaGenericImagesPage::get_page_image_urls() { - if(!chapter_image_urls.empty()) - return ImageResult::OK; - std::vector args; if(!website_url.empty()) args.push_back({ "-H", "referer: " + website_url }); diff --git a/src/plugins/Mangadex.cpp b/src/plugins/Mangadex.cpp index 3b6b2e0..6aa73b0 100644 --- a/src/plugins/Mangadex.cpp +++ b/src/plugins/Mangadex.cpp @@ -415,27 +415,8 @@ namespace QuickMedia { return true; } - ImageResult MangadexImagesPage::get_number_of_images(int &num_images) { + ImageResult MangadexImagesPage::update_image_urls(int &num_images) { num_images = 0; - ImageResult image_result = get_image_urls_for_chapter(url); - if(image_result != ImageResult::OK) return image_result; - num_images = chapter_image_urls.size(); - return ImageResult::OK; - } - - ImageResult MangadexImagesPage::for_each_page_in_chapter(PageCallback callback) { - ImageResult image_result = get_image_urls_for_chapter(url); - if(image_result != ImageResult::OK) return image_result; - for(const std::string &url : chapter_image_urls) { - if(!callback(url)) - break; - } - return ImageResult::OK; - } - - ImageResult MangadexImagesPage::get_image_urls_for_chapter(const std::string &url) { - if(!chapter_image_urls.empty()) - return ImageResult::OK; Json::Value json_root; // TODO: If this fails, call this again to retrieve another server. Also do the same for automedia @@ -476,6 +457,15 @@ namespace QuickMedia { chapter_image_urls.push_back(base_url + "data/" + hash_str + "/" + data_item_json.asString()); } + num_images = chapter_image_urls.size(); + return ImageResult::OK; + } + + ImageResult MangadexImagesPage::for_each_page_in_chapter(PageCallback callback) { + for(const std::string &url : chapter_image_urls) { + if(!callback(url)) + break; + } return ImageResult::OK; } } diff --git a/src/plugins/Manganelo.cpp b/src/plugins/Manganelo.cpp index a440743..6f0d86f 100644 --- a/src/plugins/Manganelo.cpp +++ b/src/plugins/Manganelo.cpp @@ -246,27 +246,8 @@ namespace QuickMedia { return PluginResult::OK; } - ImageResult ManganeloImagesPage::get_number_of_images(int &num_images) { + ImageResult ManganeloImagesPage::update_image_urls(int &num_images) { num_images = 0; - ImageResult image_result = get_image_urls_for_chapter(url); - if(image_result != ImageResult::OK) return image_result; - num_images = chapter_image_urls.size(); - return ImageResult::OK; - } - - ImageResult ManganeloImagesPage::for_each_page_in_chapter(PageCallback callback) { - ImageResult image_result = get_image_urls_for_chapter(url); - if(image_result != ImageResult::OK) return image_result; - for(const std::string &url : chapter_image_urls) { - if(!callback(url)) - break; - } - return ImageResult::OK; - } - - ImageResult ManganeloImagesPage::get_image_urls_for_chapter(const std::string &url) { - if(!chapter_image_urls.empty()) - return ImageResult::OK; std::string website_data; if(download_to_string(url, website_data, {CommandArg { "-H", "referer: https://manganelo.com/" }}, true) != DownloadResult::OK) @@ -294,6 +275,15 @@ namespace QuickMedia { chapter_image_urls.clear(); return ImageResult::ERR; } + num_images = chapter_image_urls.size(); + return ImageResult::OK; + } + + ImageResult ManganeloImagesPage::for_each_page_in_chapter(PageCallback callback) { + for(const std::string &url : chapter_image_urls) { + if(!callback(url)) + break; + } return ImageResult::OK; } } \ No newline at end of file -- cgit v1.2.3