From f903b027871a989c1956e6bf16b47e302a01c763 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 12 Jun 2021 04:05:03 +0200 Subject: Start from youtube url timestamp --- src/VideoPlayer.cpp | 53 +++++++++++++++++------------------------------------ 1 file changed, 17 insertions(+), 36 deletions(-) (limited to 'src/VideoPlayer.cpp') diff --git a/src/VideoPlayer.cpp b/src/VideoPlayer.cpp index adc7eb8..490ce82 100644 --- a/src/VideoPlayer.cpp +++ b/src/VideoPlayer.cpp @@ -67,20 +67,7 @@ namespace QuickMedia { XCloseDisplay(display); } - 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, const char *audio_path, sf::WindowHandle _parent_window, const std::string &plugin_name, const std::string &title) { + VideoPlayer::Error VideoPlayer::launch_video_process(const char *path, const char *audio_path, sf::WindowHandle _parent_window, const std::string &plugin_name, const std::string &title, const std::string &start_time) { parent_window = _parent_window; if(socketpair(AF_UNIX, SOCK_STREAM, 0, sockets) == -1) { @@ -103,9 +90,6 @@ namespace QuickMedia { wid_arg += parent_window_str; std::string input_conf = "--input-conf=" + resource_root + "input.conf"; - //Path video_cache_dir = get_cache_dir().join("video"); - //create_directory_recursive(video_cache_dir); - //std::string cache_dir = "--cache-dir=" + video_cache_dir.data; Path mpv_watch_later_dir = get_storage_dir().join("mpv").join("watch_later"); if(create_directory_recursive(mpv_watch_later_dir) != 0) @@ -128,9 +112,7 @@ namespace QuickMedia { "--no-terminal", "--save-position-on-quit=yes", "--profile=pseudo-gui", // For gui when playing audio, requires a version of mpv that isn't ancient - //cache_dir.c_str(), watch_later_dir.c_str(), - //"--cache-on-disk=yes", ytdl_format.c_str(), // TODO: Disable hr seek on low power devices? "--hr-seek=yes", @@ -149,7 +131,9 @@ namespace QuickMedia { if(keep_open) args.push_back("--keep-open=yes"); - if(!resume_playback) + if(resume_playback) + args.push_back("--resume-playback"); + else args.push_back("--no-resume-playback"); if(!use_system_mpv_config) { @@ -161,31 +145,27 @@ namespace QuickMedia { }); } - //std::string ytdl_options_arg; - //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()); - //} - std::string force_media_title_arg; - if(!title.empty()) + if(!title.empty()) { force_media_title_arg = "--force-media-title=" + title; - - if(!force_media_title_arg.empty()) args.push_back(force_media_title_arg.c_str()); + } if(no_video) args.push_back("--no-video"); - std::string audio_file_arg = "--audio-file="; + std::string audio_file_arg; if(audio_path && audio_path[0] != '\0') { - audio_file_arg += audio_path; + audio_file_arg = std::string("--audio-file=") + audio_path; args.push_back(audio_file_arg.c_str()); } + std::string start_time_arg; + if(!resume_playback && !start_time.empty()) { + start_time_arg = "--start=" + start_time; + args.push_back(start_time_arg.c_str()); + } + args.insert(args.end(), { "--", path, nullptr }); if(exec_program_async(args.data(), &video_process_id) != 0) { @@ -204,15 +184,16 @@ namespace QuickMedia { return Error::OK; } - VideoPlayer::Error VideoPlayer::load_video(const char *path, const char *audio_path, sf::WindowHandle _parent_window, const std::string &plugin_name, const std::string &title) { + VideoPlayer::Error VideoPlayer::load_video(const char *path, const char *audio_path, sf::WindowHandle _parent_window, const std::string &plugin_name, const std::string &title, const std::string &start_time) { // This check is to make sure we dont change window that the video belongs to. This is not a usecase we will have so // no need to support it for now at least. assert(parent_window == 0 || parent_window == _parent_window); assert(path); fprintf(stderr, "Playing video: %s, audio: %s\n", path ? path : "", audio_path ? audio_path : ""); if(video_process_id == -1) - return launch_video_process(path, audio_path, _parent_window, plugin_name, title); + return launch_video_process(path, audio_path, _parent_window, plugin_name, title, start_time); + // TODO: When these are used, add audio_path, title and start_time. Also handle plugin_name Json::Value command_data(Json::arrayValue); command_data.append("loadfile"); command_data.append(path); -- cgit v1.2.3