From e66d24f74d5458241d869fb3df42b4f2a2ea69f4 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 6 May 2021 08:18:38 +0200 Subject: Show youtube recommendations instead of local recommendations from related videos --- src/VideoPlayer.cpp | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) (limited to 'src/VideoPlayer.cpp') diff --git a/src/VideoPlayer.cpp b/src/VideoPlayer.cpp index a6f3640..5f860d2 100644 --- a/src/VideoPlayer.cpp +++ b/src/VideoPlayer.cpp @@ -63,7 +63,20 @@ namespace QuickMedia { XCloseDisplay(display); } - VideoPlayer::Error VideoPlayer::launch_video_process(const char *path, sf::WindowHandle _parent_window, const std::string&, const std::string&) { + static std::string escape_quotes(const std::string &str) { + std::string result; + for(char c : str) { + if(c == '"') + result += "\\\""; + else if(c == '\\') + result += "\\\\"; + else + result += c; + } + return result; + } + + VideoPlayer::Error VideoPlayer::launch_video_process(const char *path, sf::WindowHandle _parent_window, const std::string &plugin_name, const std::string &) { parent_window = _parent_window; if(!tmpnam(ipc_server_path)) { @@ -71,6 +84,10 @@ namespace QuickMedia { return Error::FAIL_TO_GENERATE_IPC_FILENAME; } + Path cookies_filepath; + if(get_cookies_filepath(cookies_filepath, plugin_name) != 0) + fprintf(stderr, "Failed to create %s cookies filepath\n", plugin_name.c_str()); + const std::string parent_window_str = std::to_string(parent_window); std::vector args; @@ -94,6 +111,8 @@ namespace QuickMedia { else ytdl_format = "--ytdl-format=bestvideo[height<=?" + std::to_string(monitor_height) + "]+bestaudio/best"; + std::string cookies_file_arg = "--cookies-file=" + cookies_filepath.data; + // TODO: Resume playback if the last video played matches the first video played next time QuickMedia is launched args.insert(args.end(), { "mpv", @@ -105,11 +124,12 @@ namespace QuickMedia { cache_dir.c_str(), watch_later_dir.c_str(), "--cache-on-disk=yes", - "--ytdl-raw-options=sub-lang=\"en,eng,enUS,en-US\",write-sub=", ytdl_format.c_str(), // TODO: Disable hr seek on low power devices? "--hr-seek=yes", "--gpu-context=x11egl", + "--cookies", + cookies_file_arg.c_str(), input_conf.c_str(), wid_arg.c_str() }); @@ -129,18 +149,14 @@ namespace QuickMedia { }); } - /* std::string ytdl_options_arg; - if(!plugin_name.empty()) { - Path cookies_filepath; - if(get_cookies_filepath(cookies_filepath, plugin_name) != 0) { - fprintf(stderr, "Warning: Failed to create %s cookies file\n", plugin_name.c_str()); - } else { - ytdl_options_arg = "--ytdl-raw-options=cookies=" + cookies_filepath.data; - args.push_back(ytdl_options_arg.c_str()); - } + if(plugin_name.empty()) { + ytdl_options_arg = "--ytdl-raw-options=sub-lang=\"en,eng,enUS,en-US\",write-sub="; + args.push_back(ytdl_options_arg.c_str()); + } else { + ytdl_options_arg = "--ytdl-raw-options=sub-lang=\"en,eng,enUS,en-US\",write-sub=,mark-watched=,cookies=\"" + escape_quotes(cookies_filepath.data) + "\""; + args.push_back(ytdl_options_arg.c_str()); } - */ if(no_video) args.push_back("--no-video"); -- cgit v1.2.3