From 47a057cc5a7b26d150bfa9b081bf081542280344 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 17 Aug 2022 18:35:42 +0200 Subject: Mangakatana: try different image mirror if download fails --- src/QuickMedia.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/QuickMedia.cpp') diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index ebd6ac4..7770f1e 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -3862,6 +3862,7 @@ namespace QuickMedia { std::vector extra_args; const bool is_manganelo = (strcmp(images_page->get_service_name(), "manganelo") == 0); + const bool is_mangakatana = (strcmp(images_page->get_service_name(), "mangakatana") == 0); const char *website_url = images_page->get_website_url(); if(is_manganelo) { extra_args = { @@ -3892,9 +3893,25 @@ namespace QuickMedia { } } else { int64_t file_size = 0; - if(download_to_file(url, image_filepath_tmp.data, extra_args, true) != DownloadResult::OK || (is_manganelo && file_get_size(image_filepath_tmp, &file_size) == 0 && file_size < 255)) { + bool download_success = download_to_file(url, image_filepath_tmp.data, extra_args, true) == DownloadResult::OK; + if(!download_success) { + remove(image_filepath_tmp.data.c_str()); if(!image_download_cancel) show_notification("QuickMedia", "Failed to download image: " + url, Urgency::CRITICAL); return true; + } else if(is_manganelo && file_get_size(image_filepath_tmp, &file_size) == 0 && file_size < 255) { + remove(image_filepath_tmp.data.c_str()); + if(!image_download_cancel) show_notification("QuickMedia", "Failed to download image: " + url, Urgency::CRITICAL); + return true; + } else if(is_mangakatana && file_get_size(image_filepath_tmp, &file_size) == 0 && file_size < 255) { + remove(image_filepath_tmp.data.c_str()); + std::string new_url = url; + string_replace_all(new_url, "://i3", "://i2"); + + download_success = download_to_file(new_url, image_filepath_tmp.data, extra_args, true) == DownloadResult::OK; + if(!download_success) { + if(!image_download_cancel) show_notification("QuickMedia", "Failed to download image: " + url, Urgency::CRITICAL); + return true; + } } } -- cgit v1.2.3