From 737263bc5a123bee889530a2623dfbeb90ee30e9 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 5 May 2020 19:12:07 +0200 Subject: Fallback to backup image source if image fails to load for manganelo --- src/QuickMedia.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'src/QuickMedia.cpp') diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 8e6f04e..d7c15b1 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -1052,9 +1052,25 @@ namespace QuickMedia { return true; std::string image_content; - if(download_to_string(url, image_content, {}, current_plugin->use_tor) != DownloadResult::OK) { - show_notification("Manganelo", "Failed to download image: " + url, Urgency::CRITICAL); - return false; + if(download_to_string(url, image_content, {}, current_plugin->use_tor) != DownloadResult::OK || image_content.size() <= 255) { + bool try_backup_url = false; + std::string new_url = url; + if(string_replace_all(new_url, "s3.mkklcdnv3.com", "bu.mkklcdnbuv1.com") > 0) { + try_backup_url = true; + } else { + try_backup_url = (string_replace_all(new_url, "s41.mkklcdnv41.com", "bu.mkklcdnbuv1.com") > 0); + } + + if(try_backup_url) { + image_content.clear(); + if(download_to_string(new_url, image_content, {}, current_plugin->use_tor) != DownloadResult::OK || image_content.size() <= 255) { + show_notification("Manganelo", "Failed to download image: " + new_url, Urgency::CRITICAL); + return false; + } + } else { + show_notification("Manganelo", "Failed to download image: " + url, Urgency::CRITICAL); + return false; + } } if(file_overwrite(image_filepath, image_content) != 0) { -- cgit v1.2.3