From 65457dc196f1b56128b1dc6eeaf3a086da1a180f Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 29 Jun 2021 17:45:40 +0200 Subject: Remove debug code from download header --- include/DownloadUtils.hpp | 5 +++-- src/DownloadUtils.cpp | 10 +++------- src/QuickMedia.cpp | 3 ++- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/include/DownloadUtils.hpp b/include/DownloadUtils.hpp index ed7f766..dbac921 100644 --- a/include/DownloadUtils.hpp +++ b/include/DownloadUtils.hpp @@ -28,8 +28,9 @@ namespace QuickMedia { DownloadResult download_to_string(const std::string &url, std::string &result, const std::vector &additional_args, bool use_browser_useragent = false, bool fail_on_error = true, bool cloudflare_bypass = false, std::string *header = nullptr, int download_limit = 1024 * 1024 * 100); // 100mb download limit // Note: This function saves the content to the file atomically DownloadResult download_to_string_cache(const std::string &url, std::string &result, const std::vector &additional_args, bool use_browser_useragent = false, DownloadErrorHandler error_handler = nullptr, Path cache_path = ""); - // Note: This function saves the content to the file atomically - DownloadResult download_to_file(const std::string &url, const std::string &destination_filepath, const std::vector &additional_args, bool use_browser_useragent = false); + // Note: This function saves the content to the file atomically. + // Note: if |cloudflare_bypass| is set to true then tls is limited to version 1.1 and the user agent is changed. + DownloadResult download_to_file(const std::string &url, const std::string &destination_filepath, const std::vector &additional_args, bool use_browser_useragent = false, bool cloudflare_bypass = false); // Returns false if there was an error trying to create the download process bool download_async_gui(const std::string &url, const std::string &file_manager_start_dir, bool use_youtube_dl, bool no_video); DownloadResult download_to_json(const std::string &url, rapidjson::Document &result, const std::vector &additional_args, bool use_browser_useragent = false, bool fail_on_error = true); diff --git a/src/DownloadUtils.cpp b/src/DownloadUtils.cpp index e546bd1..afef072 100644 --- a/src/DownloadUtils.cpp +++ b/src/DownloadUtils.cpp @@ -65,10 +65,6 @@ namespace QuickMedia { if(end_of_header_found) { download_userdata->body->append(download_userdata->header->begin() + end_of_headers_index, download_userdata->header->end()); - if(download_userdata->body->find("Content-Type") != std::string::npos) { - fprintf(stderr, "Found header in body!!!!, header: |%s|, body: |%s|\n", download_userdata->header->c_str(), download_userdata->body->c_str()); - abort(); - } download_userdata->header->erase(download_userdata->header->begin() + end_of_headers_index, download_userdata->header->end()); download_userdata->header_finished = true; } @@ -266,7 +262,7 @@ namespace QuickMedia { } } - DownloadResult download_to_file(const std::string &url, const std::string &destination_filepath, const std::vector &additional_args, bool use_browser_useragent) { + DownloadResult download_to_file(const std::string &url, const std::string &destination_filepath, const std::vector &additional_args, bool use_browser_useragent, bool cloudflare_bypass) { Path tmp_filepath = destination_filepath; tmp_filepath.append(".tmp"); @@ -279,7 +275,7 @@ namespace QuickMedia { args.push_back({ "-o", tmp_filepath.data.c_str() }); std::string dummy; - DownloadResult res = download_to_string(url, dummy, std::move(args), use_browser_useragent); + DownloadResult res = download_to_string(url, dummy, std::move(args), use_browser_useragent, true, cloudflare_bypass); if(res != DownloadResult::OK) return res; if(rename_atomic(tmp_filepath.data.c_str(), destination_filepath.c_str()) != 0) { @@ -353,4 +349,4 @@ namespace QuickMedia { fprintf(stderr, "Download duration for %s: %d ms\n", url.c_str(), timer.getElapsedTime().asMilliseconds()); return parse_result.IsError() ? DownloadResult::ERR : DownloadResult::OK; } -} \ No newline at end of file +} diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 97900d3..9788c0a 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -3227,6 +3227,7 @@ namespace QuickMedia { std::vector extra_args; const bool is_manganelo = (strcmp(images_page->get_service_name(), "manganelo") == 0); const char *website_url = images_page->get_website_url(); + const bool cloudflare_bypass = (strcmp(images_page->get_service_name(), "manganelo") == 0 || strcmp(images_page->get_service_name(), "readm") == 0); if(is_manganelo) { extra_args = { CommandArg { "-H", "accept: image/jpeg,image/png,image/*,*/*;q=0.8" }, @@ -3249,7 +3250,7 @@ namespace QuickMedia { Path image_filepath_tmp(image_filepath.data + ".tmpz"); // TODO: Move to page size_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)) { + if(download_to_file(url, image_filepath_tmp.data, extra_args, true, cloudflare_bypass) != DownloadResult::OK || (is_manganelo && file_get_size(image_filepath_tmp, &file_size) == 0 && file_size < 255)) { if(!image_download_cancel) show_notification("QuickMedia", "Failed to download image: " + url, Urgency::CRITICAL); return true; } -- cgit v1.2.3