aboutsummaryrefslogtreecommitdiff
path: root/src/QuickMedia.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/QuickMedia.cpp')
-rw-r--r--src/QuickMedia.cpp63
1 files changed, 36 insertions, 27 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 79b9207..c515719 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -5945,37 +5945,44 @@ namespace QuickMedia {
window.setTitle("QuickMedia - Select where you want to save " + std::string(url));
std::string filename;
- TaskResult task_result = run_task_with_loading_screen([this, url, &filename]{
- std::string json_str;
- std::vector<const char*> args = { "youtube-dl", "--skip-download", "--print-json", "--no-warnings" };
- if(no_video)
- args.push_back("-x");
- args.insert(args.end(), { "--", url, nullptr });
- if(exec_program(args.data(), accumulate_string, &json_str) != 0)
- return false;
+ TaskResult task_result;
+ if(download_use_youtube_dl) {
+ task_result = run_task_with_loading_screen([this, url, &filename]{
+ std::string json_str;
+ std::vector<const char*> args = { "youtube-dl", "--skip-download", "--print-json", "--no-warnings" };
+ if(no_video)
+ args.push_back("-x");
+ args.insert(args.end(), { "--", url, nullptr });
+ if(exec_program(args.data(), accumulate_string, &json_str) != 0)
+ return false;
- Json::Value result;
- Json::CharReaderBuilder json_builder;
- std::unique_ptr<Json::CharReader> json_reader(json_builder.newCharReader());
- std::string json_errors;
- if(!json_reader->parse(json_str.data(), json_str.data() + json_str.size(), &result, &json_errors)) {
- fprintf(stderr, "Failed to json response, error: %s\n", json_errors.c_str());
- return false;
- }
+ Json::Value result;
+ Json::CharReaderBuilder json_builder;
+ std::unique_ptr<Json::CharReader> json_reader(json_builder.newCharReader());
+ std::string json_errors;
+ if(!json_reader->parse(json_str.data(), json_str.data() + json_str.size(), &result, &json_errors)) {
+ fprintf(stderr, "Failed to json response, error: %s\n", json_errors.c_str());
+ return false;
+ }
- const Json::Value &title_json = result["title"];
- const Json::Value &ext_json = result["ext"];
- if(title_json.isString())
- filename = title_json.asString();
+ const Json::Value &title_json = result["title"];
+ const Json::Value &ext_json = result["ext"];
+ if(title_json.isString())
+ filename = title_json.asString();
- if(ext_json.isString()) {
- if(ext_json.asCString()[0] != '.' && (filename.empty() || filename.back() != '.'))
- filename += ".";
- filename += ext_json.asString();
- }
+ if(ext_json.isString()) {
+ if(ext_json.asCString()[0] != '.' && (filename.empty() || filename.back() != '.'))
+ filename += ".";
+ filename += ext_json.asString();
+ }
- return !filename.empty();
- });
+ return !filename.empty();
+ });
+ } else {
+ task_result = run_task_with_loading_screen([url, &filename]{
+ return url_get_remote_name(url, filename, true) == DownloadResult::OK;
+ });
+ }
if(task_result == TaskResult::CANCEL) {
exit_code = 1;
@@ -6304,6 +6311,8 @@ namespace QuickMedia {
std::string save_path = save_file();
if(!save_path.empty())
return save_path;
+ } else if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) {
+ window.close();
}
}