From 3eca2373621b4fbd3189df75ada884861536113a Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 27 Mar 2021 15:54:37 +0100 Subject: bla --- src/QuickMedia.cpp | 25 +++++++++++++------------ src/VideoPlayer.cpp | 13 ++++++++++--- src/plugins/Matrix.cpp | 4 ++++ 3 files changed, 27 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index cc89146..a26f52f 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -1750,6 +1750,7 @@ namespace QuickMedia { PageType previous_page = pop_page_stack(); std::string video_url = video_page->get_url(); + std::string original_video_url = video_url; bool video_url_is_local = false; if(download_if_streaming_fails) { @@ -1836,7 +1837,7 @@ namespace QuickMedia { } video_player = std::make_unique(use_tor, no_video, use_system_mpv_config, resume_video, is_matrix, video_event_callback, on_window_create, resources_root, get_largest_monitor_height(disp)); - VideoPlayer::Error err = video_player->load_video(video_url_converted.c_str(), window.getSystemHandle(), plugin_name); + VideoPlayer::Error err = video_player->load_video(video_url_converted.c_str(), window.getSystemHandle(), plugin_name, video_title); if(err != VideoPlayer::Error::OK) { std::string err_msg = "Failed to play url: "; err_msg += video_url; @@ -1916,23 +1917,23 @@ namespace QuickMedia { bool cursor_visible = true; sf::Clock cursor_hide_timer; - auto save_video_url_to_clipboard = [&video_url_is_local, &video_url, &video_player_window, &video_player]() { - if(!video_player_window || video_url_is_local) + auto save_video_url_to_clipboard = [&original_video_url, &video_player_window, &video_player]() { + if(!video_player_window) return; - if(video_url_supports_timestamp(video_url)) { + if(video_url_supports_timestamp(original_video_url)) { // TODO: Remove timestamp (&t= or ?t=) from video_url double time_in_file; if(video_player->get_time_in_file(&time_in_file) != VideoPlayer::Error::OK) time_in_file = 0.0; - std::string clipboard = video_url; + std::string clipboard = original_video_url; if((int)time_in_file > 0) clipboard += "&t=" + std::to_string((int)time_in_file); sf::Clipboard::setString(sf::String::fromUtf8(clipboard.begin(), clipboard.end())); } else { - sf::Clipboard::setString(sf::String::fromUtf8(video_url.begin(), video_url.end())); + sf::Clipboard::setString(sf::String::fromUtf8(original_video_url.begin(), original_video_url.end())); } }; @@ -2844,10 +2845,10 @@ namespace QuickMedia { page_stack.push(PageType::IMAGE_BOARD_THREAD); current_page = PageType::VIDEO_CONTENT; watched_videos.clear(); - // TODO: Use real title thread_page->video_url = selected_item->attached_content_url; BodyItems next_items; - video_content_page(thread_page, "No title.webm", true, next_items, 0); + // TODO: Use real title + video_content_page(thread_page, "", true, next_items, 0); redraw = true; } else { if(downloading_image && load_image_future.valid()) @@ -4139,10 +4140,10 @@ namespace QuickMedia { page_stack.push(PageType::CHAT); watched_videos.clear(); current_page = PageType::VIDEO_CONTENT; - // TODO: Add title video_page->url = url; BodyItems next_items; - video_content_page(video_page.get(), "No title", false, next_items, 0); + // TODO: Add title + video_content_page(video_page.get(), "", false, next_items, 0); redraw = true; } else { const char *launch_program = "xdg-open"; @@ -4219,10 +4220,10 @@ namespace QuickMedia { bool is_audio = (message_type == MessageType::AUDIO); bool prev_no_video = no_video; no_video = is_audio; - // TODO: Add title video_page->url = selected->url; BodyItems next_items; - video_content_page(video_page.get(), "No title", message_type == MessageType::VIDEO || message_type == MessageType::AUDIO, next_items, 0); + // TODO: Add title + video_content_page(video_page.get(), "", message_type == MessageType::VIDEO || message_type == MessageType::AUDIO, next_items, 0); no_video = prev_no_video; redraw = true; return true; diff --git a/src/VideoPlayer.cpp b/src/VideoPlayer.cpp index 3b93c44..679f5bf 100644 --- a/src/VideoPlayer.cpp +++ b/src/VideoPlayer.cpp @@ -64,7 +64,7 @@ namespace QuickMedia { XCloseDisplay(display); } - VideoPlayer::Error VideoPlayer::launch_video_process(const char *path, sf::WindowHandle _parent_window, const std::string&) { + VideoPlayer::Error VideoPlayer::launch_video_process(const char *path, sf::WindowHandle _parent_window, const std::string&, const std::string &title) { parent_window = _parent_window; if(!tmpnam(ipc_server_path)) { @@ -97,6 +97,10 @@ namespace QuickMedia { else ytdl_format = "--ytdl-format=bestvideo[height<=?" + std::to_string(monitor_height) + "]+bestaudio/best"; + std::string script_opts; + if(!title.empty()) + script_opts = "--script-opts='osc-title=" + title + "'"; + // TODO: Resume playback if the last video played matches the first video played next time QuickMedia is launched args.insert(args.end(), { "mpv", @@ -122,6 +126,9 @@ namespace QuickMedia { if(!resume_playback) args.push_back("--no-resume-playback"); + if(!script_opts.empty()) + args.push_back(script_opts.c_str()); + if(!use_system_mpv_config) { args.insert(args.end(), { "--no-config", /*"--demuxer-max-bytes=40M", "--demuxer-max-back-bytes=20M",*/ @@ -168,12 +175,12 @@ namespace QuickMedia { return Error::OK; } - VideoPlayer::Error VideoPlayer::load_video(const char *path, sf::WindowHandle _parent_window, const std::string &plugin_name) { + VideoPlayer::Error VideoPlayer::load_video(const char *path, sf::WindowHandle _parent_window, const std::string &plugin_name, const std::string &title) { // 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); if(video_process_id == -1) - return launch_video_process(path, _parent_window, plugin_name); + return launch_video_process(path, _parent_window, plugin_name, title); Json::Value command_data(Json::arrayValue); command_data.append("loadfile"); diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index 1460687..220a059 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -2100,6 +2100,8 @@ namespace QuickMedia { message->thumbnail_url = message_content_extract_thumbnail_url(*content_json, homeserver); message_content_extract_thumbnail_size(*content_json, message->thumbnail_size); message->type = MessageType::VIDEO; + if(message->thumbnail_url.empty()) + prefix = "🎥 play "; } else if(strcmp(content_type.GetString(), "m.audio") == 0) { const rapidjson::Value &url_json = GetMember(*content_json, "url"); if(!url_json.IsString() || strncmp(url_json.GetString(), "mxc://", 6) != 0) @@ -2107,6 +2109,7 @@ namespace QuickMedia { message->url = homeserver + "/_matrix/media/r0/download/" + (url_json.GetString() + 6); message->type = MessageType::AUDIO; + prefix = "🎵 play "; } else if(strcmp(content_type.GetString(), "m.file") == 0) { const rapidjson::Value &url_json = GetMember(*content_json, "url"); if(!url_json.IsString() || strncmp(url_json.GetString(), "mxc://", 6) != 0) @@ -2114,6 +2117,7 @@ namespace QuickMedia { message->url = homeserver + "/_matrix/media/r0/download/" + (url_json.GetString() + 6); message->type = MessageType::FILE; + prefix = "💾 download "; } else if(strcmp(content_type.GetString(), "m.emote") == 0) { // this is a /me message, TODO: show /me messages differently message->type = MessageType::TEXT; prefix = "*" + room_data->get_user_display_name(user) + "* "; -- cgit v1.2.3