From 8ad3f9ab8cc7029eb5db937e229d2a37b51a3462 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 11 Jun 2021 06:52:04 +0200 Subject: Readd youtube video title --- src/QuickMedia.cpp | 8 ++++++-- src/VideoPlayer.cpp | 25 ++++++++++++++++--------- src/plugins/Youtube.cpp | 6 +++++- 3 files changed, 27 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 4b78117..776f70f 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -2379,10 +2379,14 @@ namespace QuickMedia { video_loaded = false; video_player_window = None; - TaskResult load_result = run_task_with_loading_screen([video_page, &channel_url]() { - return video_page->load(channel_url) == PluginResult::OK; + std::string new_title; + TaskResult load_result = run_task_with_loading_screen([video_page, &new_title, &channel_url]() { + return video_page->load(new_title, channel_url) == PluginResult::OK; }); + if(!new_title.empty()) + video_title = std::move(new_title); + if(load_result == TaskResult::CANCEL) { current_page = previous_page; return; diff --git a/src/VideoPlayer.cpp b/src/VideoPlayer.cpp index 2b0653c..4fce4e0 100644 --- a/src/VideoPlayer.cpp +++ b/src/VideoPlayer.cpp @@ -80,7 +80,7 @@ namespace QuickMedia { 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 &) { + 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) { parent_window = _parent_window; if(socketpair(AF_UNIX, SOCK_STREAM, 0, sockets) == -1) { @@ -160,14 +160,21 @@ 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 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()) + 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"); diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp index 04c29e0..d891ae3 100644 --- a/src/plugins/Youtube.cpp +++ b/src/plugins/Youtube.cpp @@ -1857,7 +1857,7 @@ namespace QuickMedia { return audio_formats.front().base.url; } - PluginResult YoutubeVideoPage::load(std::string &channel_url) { + PluginResult YoutubeVideoPage::load(std::string &title, std::string &channel_url) { video_formats.clear(); audio_formats.clear(); @@ -1905,6 +1905,10 @@ namespace QuickMedia { const Json::Value &video_details_json = json_root["videoDetails"]; if(video_details_json.isObject()) { + const Json::Value &title_json = video_details_json["title"]; + if(title_json.isString()) + title = title_json.asString(); + const Json::Value &channel_id_json = video_details_json["channelId"]; if(channel_id_json.isString()) channel_url = "https://www.youtube.com/channel/" + channel_id_json.asString(); -- cgit v1.2.3