aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Config.cpp39
-rw-r--r--src/DownloadUtils.cpp4
-rw-r--r--src/FileAnalyzer.cpp20
-rw-r--r--src/QuickMedia.cpp68
4 files changed, 108 insertions, 23 deletions
diff --git a/src/Config.cpp b/src/Config.cpp
index 540286f..3f2d68c 100644
--- a/src/Config.cpp
+++ b/src/Config.cpp
@@ -256,6 +256,45 @@ namespace QuickMedia {
if(!has_known_peertube_homeservers_config)
peertube_known_instances_fallback();
+ const std::string home_dir = get_home_dir().data;
+
+ struct DownloadPaths {
+ const char *json_field;
+ std::string fallback_dir;
+ const char *xdg_var_name;
+ std::string *config_var;
+ };
+
+ const int num_download_paths = 4;
+ DownloadPaths download_paths_list[num_download_paths] = {
+ { "video_directory", home_dir + "/Videos", "XDG_VIDEOS_DIR", &config->download.video_directory },
+ { "image_directory", home_dir + "/Pictures", "XDG_PICTURES_DIR", &config->download.image_directory },
+ { "music_directory", home_dir + "/Music", "XDG_MUSIC_DIR", &config->download.music_directory },
+ { "file_directory", home_dir + "/Downloads", "XDG_DOWNLOAD_DIR", &config->download.file_directory },
+ };
+
+ const Json::Value &download_json = json_root["download"];
+ if(download_json.isObject()) {
+ for(const DownloadPaths &download_paths : download_paths_list) {
+ const Json::Value &directory_json = download_json[download_paths.json_field];
+ if(!directory_json.isString()) {
+ fprintf(stderr, "Warning: config variable config.download.%s is not a string, using path \"%s\" instead\n", download_paths.json_field, download_paths.fallback_dir.c_str());
+ continue;
+ }
+ *download_paths.config_var = path_expanduser(directory_json.asString());
+ }
+ }
+
+ for(const DownloadPaths &download_paths : download_paths_list) {
+ if(download_paths.config_var->empty()) {
+ std::string dir = download_paths.fallback_dir;
+ const char *xdg_var = getenv(download_paths.xdg_var_name);
+ if(xdg_var)
+ dir = xdg_var;
+ *download_paths.config_var = std::move(dir);
+ }
+ }
+
get_json_value(json_root, "use_system_fonts", config->use_system_fonts);
get_json_value(json_root, "use_system_mpv_config", config->use_system_mpv_config);
get_json_value(json_root, "enable_shaders", config->enable_shaders);
diff --git a/src/DownloadUtils.cpp b/src/DownloadUtils.cpp
index 484afeb..3fb8b19 100644
--- a/src/DownloadUtils.cpp
+++ b/src/DownloadUtils.cpp
@@ -318,7 +318,7 @@ namespace QuickMedia {
return DownloadResult::OK;
}
- bool download_async_gui(const std::string &url, const std::string &file_manager_start_dir, bool no_video, const std::string &filename) {
+ bool download_async_gui(const std::string &url, const std::string &file_manager_start_dir, bool no_video, const std::string &filename, bool download_no_dialog) {
char quickmedia_path[PATH_MAX];
ssize_t bytes_written = readlink("/proc/self/exe", quickmedia_path, sizeof(quickmedia_path) - 1);
if(bytes_written == -1)
@@ -329,6 +329,8 @@ namespace QuickMedia {
std::vector<const char*> args = { quickmedia_path, "download", "-u", url.c_str(), "--dir", file_manager_start_dir.c_str() };
if(no_video)
args.push_back("--no-video");
+ if(download_no_dialog)
+ args.push_back("--no-dialog");
if(!filename.empty())
args.insert(args.end(), { "--download-filename", filename.c_str() });
args.push_back(nullptr);
diff --git a/src/FileAnalyzer.cpp b/src/FileAnalyzer.cpp
index 0f312cf..b02d0c2 100644
--- a/src/FileAnalyzer.cpp
+++ b/src/FileAnalyzer.cpp
@@ -108,7 +108,7 @@ namespace QuickMedia {
|| strcase_equals(ext, ".flv")
|| strcase_equals(ext, ".vob")
|| strcase_equals(ext, ".ogv")
- || strcase_equals(ext, ".ogg")
+ //|| strcase_equals(ext, ".ogg")
|| strcase_equals(ext, ".avi")
//|| strcase_equals(ext, ".ts")
|| strcase_equals(ext, ".mov")
@@ -121,6 +121,24 @@ namespace QuickMedia {
|| strcase_equals(ext, ".3gp");
}
+ bool is_music_ext(const char *ext) {
+ return strcase_equals(ext, ".aac")
+ || strcase_equals(ext, ".alac")
+ || strcase_equals(ext, ".flac")
+ || strcase_equals(ext, ".m4a")
+ || strcase_equals(ext, ".m4p")
+ || strcase_equals(ext, ".mp3")
+ || strcase_equals(ext, ".ogg")
+ || strcase_equals(ext, ".oga")
+ || strcase_equals(ext, ".mogg")
+ || strcase_equals(ext, ".opus")
+ || strcase_equals(ext, ".vox")
+ || strcase_equals(ext, ".wav")
+ || strcase_equals(ext, ".wma")
+ || strcase_equals(ext, ".mid");
+
+ }
+
static int accumulate_string(char *data, int size, void *userdata) {
std::string *str = (std::string*)userdata;
str->append(data, size);
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 44b1315..fbf2006 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -384,6 +384,7 @@ namespace QuickMedia {
std::string program_path = dirname(argv[0]);
std::string instance;
std::string download_filename;
+ bool no_dialog = false;
for(int i = 1; i < argc; ++i) {
if(!plugin_name) {
@@ -481,6 +482,8 @@ namespace QuickMedia {
usage();
return -1;
}
+ } else if(strcmp(argv[i], "--no-dialog") == 0) {
+ no_dialog = true;
} else if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
usage();
return 0;
@@ -560,7 +563,7 @@ namespace QuickMedia {
};
no_video = force_no_video;
- init(parent_window, program_path);
+ init(parent_window, program_path, no_dialog);
if(strcmp(plugin_name, "download") == 0) {
if(!url) {
@@ -568,7 +571,7 @@ namespace QuickMedia {
usage();
return -1;
}
- download_page(url, download_filename);
+ download_page(url, download_filename, no_dialog);
return exit_code;
}
@@ -641,7 +644,7 @@ namespace QuickMedia {
return focused_monitor_center;
}
- void Program::init(mgl::WindowHandle parent_window, std::string &program_path) {
+ void Program::init(mgl::WindowHandle parent_window, std::string &program_path, bool no_dialog) {
disp = XOpenDisplay(NULL);
if (!disp) {
show_notification("QuickMedia", "Failed to open display to X11 server", Urgency::CRITICAL);
@@ -669,6 +672,7 @@ namespace QuickMedia {
window_create_params.min_size = window_size;
window_create_params.max_size = window_size;
}
+ window_create_params.hidden = no_dialog;
window_create_params.parent_window = parent_window;
if(!window.create("QuickMedia", std::move(window_create_params))) {
show_notification("QuickMedia", "Failed to create opengl window", Urgency::CRITICAL);
@@ -3058,7 +3062,7 @@ namespace QuickMedia {
redirect_focus_to_video_player_window(video_player_window);
}
- void Program::video_page_download_video(const std::string &url, const std::string &filename, mgl::WindowHandle video_player_window) {
+ void Program::video_page_download_video(const std::string &url, const std::string &filename, mgl::WindowHandle video_player_window, bool download_no_dialog) {
bool separate_audio_option = url_should_download_with_youtube_dl(url);
std::string video_id;
separate_audio_option |= youtube_url_extract_id(url, video_id);
@@ -3067,7 +3071,7 @@ namespace QuickMedia {
separate_audio_option = false;
if(!separate_audio_option) {
- download_async_gui(url, file_manager_start_dir.string(), no_video, filename);
+ download_async_gui(url, file_manager_start_dir.string(), no_video, filename, download_no_dialog);
return;
}
@@ -3097,7 +3101,7 @@ namespace QuickMedia {
if(!selected)
return;
- download_async_gui(url, file_manager_start_dir.string(), audio_only, filename);
+ download_async_gui(url, file_manager_start_dir.string(), audio_only, filename, download_no_dialog);
}
bool Program::video_download_if_non_streamable(std::string &video_url, std::string &audio_url, bool &is_audio_only, bool &has_embedded_audio, PageType previous_page) {
@@ -3595,7 +3599,8 @@ namespace QuickMedia {
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
KeySym pressed_keysym = XKeycodeToKeysym(disp, xev.xkey.keycode, 0);
#pragma GCC diagnostic pop
- bool pressing_ctrl = (CLEANMASK(xev.xkey.state) == ControlMask);
+ const bool pressing_ctrl = (CLEANMASK(xev.xkey.state) & ControlMask);
+ const bool pressing_shift = (CLEANMASK(xev.xkey.state) & ShiftMask);
if(pressed_keysym == XK_q && pressing_ctrl) {
window.close();
} else if(pressed_keysym == XK_Escape || pressed_keysym == XK_BackSpace) {
@@ -3614,7 +3619,8 @@ namespace QuickMedia {
} else if(pressed_keysym == XK_f && pressing_ctrl) {
video_player->cycle_fullscreen();
} else if(pressed_keysym == XK_s && pressing_ctrl && !video_page->is_local()) {
- video_page_download_video(video_page->get_download_url(video_get_max_height()), video_page->get_filename(), video_player_window);
+ const bool download_no_dialog = pressing_shift;
+ video_page_download_video(video_page->get_download_url(video_get_max_height()), video_page->get_filename(), video_player_window, download_no_dialog);
} else if(pressed_keysym == XK_F5 && !video_page->is_local()) {
double resume_start_time = 0.0;
video_player->get_time_in_file(&resume_start_time);
@@ -4777,7 +4783,7 @@ namespace QuickMedia {
} else if(event.key.code == mgl::Keyboard::S && event.key.control) {
BodyItem *selected_item = thread_body->get_selected();
if(selected_item && !selected_item->url.empty())
- download_async_gui(selected_item->url, file_manager_start_dir.string(), false, "");
+ download_async_gui(selected_item->url, file_manager_start_dir.string(), false, "", event.key.shift);
}
BodyItem *selected_item = thread_body->get_selected();
@@ -4905,7 +4911,7 @@ namespace QuickMedia {
redraw = true;
frame_skip_text_entry = true;
} else if(event.key.code == mgl::Keyboard::S && event.key.control) {
- download_async_gui(attached_image_url, file_manager_start_dir.string(), false, "");
+ download_async_gui(attached_image_url, file_manager_start_dir.string(), false, "", event.key.shift);
}
}
}
@@ -6556,7 +6562,7 @@ namespace QuickMedia {
avatar_applied = false;
return true;
} else if(message_type == MessageType::FILE) {
- download_async_gui(selected->url, file_manager_start_dir.string(), no_video, filename);
+ download_async_gui(selected->url, file_manager_start_dir.string(), no_video, filename, false);
return true;
}
@@ -6582,7 +6588,7 @@ namespace QuickMedia {
return false;
};
- auto download_selected_item = [this, &ui_tabs, PINNED_TAB_INDEX, MESSAGES_TAB_INDEX](BodyItem *selected) {
+ auto download_selected_item = [this, &ui_tabs, PINNED_TAB_INDEX, MESSAGES_TAB_INDEX](BodyItem *selected, bool no_dialog) {
if(!selected)
return false;
@@ -6609,7 +6615,7 @@ namespace QuickMedia {
else if(string_starts_with(filename, file_prefix))
filename.erase(filename.begin(), filename.begin() + strlen(file_prefix));
- download_async_gui(selected->url, file_manager_start_dir.string(), no_video, filename);
+ download_async_gui(selected->url, file_manager_start_dir.string(), no_video, filename, no_dialog);
return true;
}
}
@@ -6890,8 +6896,8 @@ namespace QuickMedia {
} else if(event.key.code == mgl::Keyboard::S && event.key.control) {
BodyItem *selected = tabs[selected_tab].body->get_selected();
if(selected) {
- if(!download_selected_item(selected))
- download_selected_item(selected->embedded_item.get());
+ if(!download_selected_item(selected, event.key.shift))
+ download_selected_item(selected->embedded_item.get(), event.key.shift);
}
}
}
@@ -7819,7 +7825,7 @@ namespace QuickMedia {
return 0;
}
- void Program::download_page(std::string url, std::string download_filename) {
+ void Program::download_page(std::string url, std::string download_filename, bool no_dialog) {
window.set_title(("QuickMedia - Select where you want to save " + std::string(url)).c_str());
url = invidious_url_to_youtube_url(url);
@@ -7970,10 +7976,25 @@ namespace QuickMedia {
}
string_replace_all(filename, '/', '_');
- std::string output_filepath = file_save_page(filename);
- if(!window.is_open() || output_filepath.empty()) {
- exit_code = 1;
- return;
+ std::string output_filepath;
+ if(no_dialog) {
+ std::string filename_ext = Path(filename).ext();
+ if(is_video_ext(filename_ext.c_str()))
+ output_filepath = get_config().download.video_directory;
+ else if(is_image_ext(filename_ext.c_str()))
+ output_filepath = get_config().download.image_directory;
+ else if(is_music_ext(filename_ext.c_str()))
+ output_filepath = get_config().download.music_directory;
+ else
+ output_filepath = get_config().download.file_directory;
+ output_filepath += "/" + filename;
+ } else {
+ window.set_visible(true);
+ output_filepath = file_save_page(filename);
+ if(!window.is_open() || output_filepath.empty()) {
+ exit_code = 1;
+ return;
+ }
}
mgl::vec2i monitor_size;
@@ -7984,10 +8005,15 @@ namespace QuickMedia {
window.set_size_limits(window_size, window_size);
window.set_position(mgl::vec2i(focused_monitor_center.x - window_size.x * 0.5f, focused_monitor_center.y - window_size.y * 0.5f));
+ std::string window_title = "QuickMedia - downloading ";
+ window_title += Path(output_filepath).filename();
+ window.set_title(window_title.c_str());
+ window.set_visible(true);
+
std::string output_filepath_s = output_filepath;
char *output_dir = dirname(output_filepath_s.data());
if(create_directory_recursive(output_dir) != 0) {
- show_notification("QuickMedia", std::string("Failed to download ") + url + " to " + output_filepath, Urgency::CRITICAL);
+ show_notification("QuickMedia", std::string("Failed to download ") + url + " to " + output_filepath + " (failed to create directory)", Urgency::CRITICAL);
exit_code = 1;
return;
}