diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-10-19 14:44:55 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-10-19 14:44:55 +0200 |
commit | 1569d02aa38baa53d5442b3babdbf1a3aaa3aaa0 (patch) | |
tree | e2d58b2ad86168c238f996e699097ca1d3991a47 /src/DownloadUtils.cpp | |
parent | 1ea92d1aa4656160fee3059500c405ce4260bce7 (diff) |
Load thumbnails with multiple threads, use sha256 for saving image to path instead of base64 (filename limit is 256 on linux...)
Diffstat (limited to 'src/DownloadUtils.cpp')
-rw-r--r-- | src/DownloadUtils.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/DownloadUtils.cpp b/src/DownloadUtils.cpp index 8782020..fd7e7d1 100644 --- a/src/DownloadUtils.cpp +++ b/src/DownloadUtils.cpp @@ -80,6 +80,31 @@ namespace QuickMedia { } } + // TODO: Use this everywhere we want to save to file (such as manga download) + DownloadResult download_to_file(const std::string &url, const std::string &destination_filepath, const std::vector<CommandArg> &additional_args, bool use_tor, bool use_browser_useragent) { + Path tmp_filepath = destination_filepath; + tmp_filepath.append(".tmp"); + + // TODO: Optimize with temporary '\0' + size_t dir_end = tmp_filepath.data.rfind('/'); + if(dir_end != std::string::npos && create_directory_recursive(tmp_filepath.data.substr(0, dir_end)) != 0) + return DownloadResult::ERR; + + std::vector<CommandArg> args = additional_args; + args.push_back({ "-o", tmp_filepath.data.c_str() }); + + std::string dummy; + DownloadResult res = download_to_string(url, dummy, std::move(args), use_tor, use_browser_useragent); + if(res != DownloadResult::OK) return res; + + if(rename(tmp_filepath.data.c_str(), destination_filepath.c_str()) != 0) { + perror("rename"); + return DownloadResult::ERR; + } + + return DownloadResult::OK; + } + // TODO: Add timeout DownloadResult download_to_json(const std::string &url, rapidjson::Document &result, const std::vector<CommandArg> &additional_args, bool use_tor, bool use_browser_useragent, bool fail_on_error) { sf::Clock timer; |