diff options
Diffstat (limited to 'src/DownloadUtils.cpp')
-rw-r--r-- | src/DownloadUtils.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/DownloadUtils.cpp b/src/DownloadUtils.cpp index 2a3f9d3..dae013d 100644 --- a/src/DownloadUtils.cpp +++ b/src/DownloadUtils.cpp @@ -52,9 +52,16 @@ namespace QuickMedia { return DownloadResult::OK; } - DownloadResult download_to_string_cache(const std::string &url, std::string &result, const std::vector<CommandArg> &additional_args, bool use_tor, bool use_browser_useragent, DownloadErrorHandler error_handler) { - Path media_dir = get_cache_dir().join("media"); - Path media_file_path = Path(media_dir).join(base64_url::encode(url)); + DownloadResult download_to_string_cache(const std::string &url, std::string &result, const std::vector<CommandArg> &additional_args, bool use_tor, bool use_browser_useragent, DownloadErrorHandler error_handler, Path cache_path) { + Path media_dir; + Path media_file_path; + if(cache_path.data.empty()) { + media_dir = get_cache_dir().join("media"); + media_file_path = Path(media_dir).join(base64_url::encode(url)); + } else { + media_dir = cache_path.parent(); + media_file_path = std::move(cache_path); + } if(get_file_type(media_file_path) == FileType::REGULAR) { if(file_get_content(media_file_path, result) == 0) { fprintf(stderr, "Loaded %s from cache\n", url.c_str()); @@ -65,8 +72,8 @@ namespace QuickMedia { } } else { DownloadResult download_result = download_to_string(url, result, additional_args, use_tor, use_browser_useragent, error_handler ? false : true); - if(!error_handler(result)) - download_result = DownloadResult::ERR; + if(error_handler) + download_result = error_handler(result) ? DownloadResult::OK : DownloadResult::ERR; if(download_result == DownloadResult::OK) { Path media_file_path_tmp(media_file_path.data + ".tmp"); if(create_directory_recursive(media_dir) == 0 && file_overwrite(media_file_path_tmp, result) == 0) { |