From 38874aa9c8bfcf12bd1ceef013a2342da5a0eeea Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 2 Oct 2020 20:03:24 +0200 Subject: Add --no-video option to play videos with only audio --- src/QuickMedia.cpp | 7 +++++-- src/VideoPlayer.cpp | 6 +++++- src/plugins/Matrix.cpp | 4 ++-- 3 files changed, 12 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 29b2db9..bd9b091 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -280,9 +280,10 @@ namespace QuickMedia { } static void usage() { - fprintf(stderr, "usage: QuickMedia [--tor] [--use-system-mpv-config] [--dir ] [-p ]\n"); + fprintf(stderr, "usage: QuickMedia [--tor] [--no-video] [--use-system-mpv-config] [--dir ] [-p ]\n"); fprintf(stderr, "OPTIONS:\n"); fprintf(stderr, " plugin The plugin to use. Should be either 4chan, manganelo, mangatown, mangadex, pornhub, youtube, nyaa.si, matrix, file-manager or dmenu\n"); + fprintf(stderr, " --no-video Only play audio when playing a video. Disabled by default\n"); fprintf(stderr, " --tor Use tor. Disabled by default\n"); fprintf(stderr, " --use-system-mpv-config Use system mpv config instead of no config. Disabled by default\n"); fprintf(stderr, " --upscale-images Upscale low-resolution manga pages using waifu2x-ncnn-vulkan. Disabled by default\n"); @@ -363,6 +364,8 @@ namespace QuickMedia { if(strcmp(argv[i], "--tor") == 0) { use_tor = true; + } else if(strcmp(argv[i], "--no-video") == 0) { + no_video = true; } else if(strcmp(argv[i], "--use-system-mpv-config") == 0) { use_system_mpv_config = true; } else if(strcmp(argv[i], "--upscale-images") == 0) { @@ -1583,7 +1586,7 @@ namespace QuickMedia { } }; - video_player = std::make_unique(current_plugin->use_tor, use_system_mpv_config, video_event_callback, on_window_create, resources_root); + video_player = std::make_unique(use_tor, no_video, use_system_mpv_config, video_event_callback, on_window_create, resources_root); load_video_error_check(); sf::Event event; diff --git a/src/VideoPlayer.cpp b/src/VideoPlayer.cpp index 0b173dd..a79ffd7 100644 --- a/src/VideoPlayer.cpp +++ b/src/VideoPlayer.cpp @@ -18,9 +18,10 @@ const int MAX_RETRIES_CONNECT = 20; const int READ_TIMEOUT_MS = 200; namespace QuickMedia { - VideoPlayer::VideoPlayer(bool use_tor, bool use_system_mpv_config, EventCallbackFunc _event_callback, VideoPlayerWindowCreateCallback _window_create_callback, const std::string &resource_root) : + VideoPlayer::VideoPlayer(bool use_tor, bool no_video, bool use_system_mpv_config, EventCallbackFunc _event_callback, VideoPlayerWindowCreateCallback _window_create_callback, const std::string &resource_root) : exit_status(0), use_tor(use_tor), + no_video(no_video), use_system_mpv_config(use_system_mpv_config), video_process_id(-1), ipc_socket(-1), @@ -113,6 +114,9 @@ namespace QuickMedia { } */ + if(no_video) + args.push_back("--no-video"); + args.insert(args.end(), { "--", path, nullptr }); if(exec_program_async(args.data(), &video_process_id) != 0) diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index b8f3742..9ba1b6b 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -905,7 +905,7 @@ namespace QuickMedia { } static std::string block_quote(const std::string &str) { - std::string result = "> "; + std::string result; for(char c : str) { if(c == '>') { result += "\\>"; @@ -941,7 +941,7 @@ namespace QuickMedia { related_to_body = "sent a file"; break; } - return block_quote("<" + room_data->user_info[message->user_id].user_id + "> " + std::move(related_to_body)) + "\n\n" + body; + return "> <" + room_data->user_info[message->user_id].user_id + "> " + block_quote(std::move(related_to_body)) + "\n\n" + body; } // TODO: Add formatted_body just like element does with