diff options
author | dec05eba <dec05eba@protonmail.com> | 2022-02-13 19:19:31 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2022-02-13 19:19:31 +0100 |
commit | e65d0b4effdbbcc9393c58075c010f59231fd45e (patch) | |
tree | 326adbee3f4387c06892dc1a448b5dc4244d54ca /src | |
parent | 15708005417840782f7cafeee99d50fc112d49f6 (diff) |
Make manga images pages less error prone
Diffstat (limited to 'src')
-rw-r--r-- | src/QuickMedia.cpp | 2 | ||||
-rw-r--r-- | src/plugins/LocalManga.cpp | 30 | ||||
-rw-r--r-- | src/plugins/MangaGeneric.cpp | 20 | ||||
-rw-r--r-- | src/plugins/Mangadex.cpp | 30 | ||||
-rw-r--r-- | src/plugins/Manganelo.cpp | 30 |
5 files changed, 33 insertions, 79 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index edb1db1..3ef29b5 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -3438,7 +3438,7 @@ namespace QuickMedia { Path content_cache_dir_ = content_cache_dir; image_download_future = AsyncTask<void, std::promise<int>>([images_page, content_cache_dir_, this](std::promise<int> num_manga_pages_promise) { int num_pages = 0; - if(images_page->get_number_of_images(num_pages) != ImageResult::OK) { + if(images_page->update_image_urls(num_pages) != ImageResult::OK) { num_manga_pages_promise.set_value(0); if(!image_download_cancel) show_notification("QuickMedia", "Failed to fetch page images", Urgency::CRITICAL); return; 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<LocalMangaPage> 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<CommandArg> 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 |