From 52d2bcde946b4cc05932db347bce44d2fd518865 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 28 Jun 2020 00:03:27 +0200 Subject: Add --use-system-mpv-config option --- README.md | 5 +++-- include/QuickMedia.hpp | 2 ++ include/VideoPlayer.hpp | 3 ++- src/QuickMedia.cpp | 10 ++++++---- src/VideoPlayer.cpp | 30 ++++++++++++++++++------------ 5 files changed, 31 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 3f46c6b..438b65d 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,9 @@ Cache is stored under `$HOME/.cache/quickmedia`. ``` usage: QuickMedia [--tor] OPTIONS: -plugin The plugin to use. Should be either 4chan, manganelo, mangatown, mangadex, youtube or dmenu ---tor Use tor. Disabled by default +plugin The plugin to use. Should be either 4chan, manganelo, mangatown, mangadex, youtube or dmenu +--tor Use tor. Disabled by default +--use-system-mpv-config Use system mpv config instead of no config. Disabled by default EXAMPLES: QuickMedia manganelo QuickMedia youtube --tor diff --git a/include/QuickMedia.hpp b/include/QuickMedia.hpp index dc81425..2e14b09 100644 --- a/include/QuickMedia.hpp +++ b/include/QuickMedia.hpp @@ -82,5 +82,7 @@ namespace QuickMedia { bool image_download_cancel = false; int exit_code = 0; std::string resources_root; + bool use_tor = false; + bool use_system_mpv_config = false; }; } \ No newline at end of file diff --git a/include/VideoPlayer.hpp b/include/VideoPlayer.hpp index e1763f6..4dc7b53 100644 --- a/include/VideoPlayer.hpp +++ b/include/VideoPlayer.hpp @@ -35,7 +35,7 @@ namespace QuickMedia { }; // @event_callback is called from another thread - VideoPlayer(bool use_tor, EventCallbackFunc event_callback, VideoPlayerWindowCreateCallback window_create_callback); + VideoPlayer(bool use_tor, bool use_system_mpv_config, EventCallbackFunc event_callback, VideoPlayerWindowCreateCallback window_create_callback); ~VideoPlayer(); VideoPlayer(const VideoPlayer&) = delete; VideoPlayer& operator=(const VideoPlayer&) = delete; @@ -66,6 +66,7 @@ namespace QuickMedia { VideoPlayer::Error read_ipc_func(); private: bool use_tor; + bool use_system_mpv_config; pid_t video_process_id; int ipc_socket; bool connected_to_ipc; diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index aa14d11..aba9485 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -106,8 +106,9 @@ namespace QuickMedia { static void usage() { fprintf(stderr, "usage: QuickMedia [--tor]\n"); fprintf(stderr, "OPTIONS:\n"); - fprintf(stderr, "plugin The plugin to use. Should be either 4chan, manganelo, mangatown, mangadex, pornhub, youtube or dmenu\n"); - fprintf(stderr, "--tor Use tor. Disabled by default\n"); + fprintf(stderr, "plugin The plugin to use. Should be either 4chan, manganelo, mangatown, mangadex, pornhub, youtube or dmenu\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, "EXAMPLES:\n"); fprintf(stderr, "QuickMedia manganelo\n"); fprintf(stderr, "QuickMedia youtube --tor\n"); @@ -141,7 +142,6 @@ namespace QuickMedia { current_plugin = nullptr; std::string plugin_logo_path; - bool use_tor = false; for(int i = 1; i < argc; ++i) { if(!current_plugin) { @@ -170,6 +170,8 @@ namespace QuickMedia { if(strcmp(argv[i], "--tor") == 0) { use_tor = true; + } else if(strcmp(argv[i], "--use-system-mpv-config") == 0) { + use_system_mpv_config = true; } } @@ -662,7 +664,7 @@ namespace QuickMedia { }; bool has_video_started = true; - video_player = std::make_unique(current_plugin->use_tor, [this, &video_player, &seekable, &load_video_error_check, previous_page, &has_video_started](const char *event_name) mutable { + video_player = std::make_unique(current_plugin->use_tor, use_system_mpv_config, [this, &video_player, &seekable, &load_video_error_check, previous_page, &has_video_started](const char *event_name) mutable { bool end_of_file = false; if(strcmp(event_name, "pause") == 0) { double time_remaining = 9999.0; diff --git a/src/VideoPlayer.cpp b/src/VideoPlayer.cpp index 85c0d4d..138f269 100644 --- a/src/VideoPlayer.cpp +++ b/src/VideoPlayer.cpp @@ -17,8 +17,9 @@ const int MAX_RETRIES_CONNECT = 20; const int READ_TIMEOUT_MS = 200; namespace QuickMedia { - VideoPlayer::VideoPlayer(bool use_tor, EventCallbackFunc _event_callback, VideoPlayerWindowCreateCallback _window_create_callback) : + VideoPlayer::VideoPlayer(bool use_tor, bool use_system_mpv_config, EventCallbackFunc _event_callback, VideoPlayerWindowCreateCallback _window_create_callback) : use_tor(use_tor), + use_system_mpv_config(use_system_mpv_config), video_process_id(-1), ipc_socket(-1), connected_to_ipc(false), @@ -74,18 +75,23 @@ namespace QuickMedia { wid_arg += parent_window_str; // TODO: Resume playback if the last video played matches the first video played next time QuickMedia is launched - args.insert(args.end(), { "mpv", "--keep-open=yes", /*"--keep-open-pause=no",*/ input_ipc_server_arg.c_str(), - "--no-config", - //"--no-input-default-bindings", "--input-vo-keyboard=no", - "--demuxer-max-bytes=40M", "--demuxer-max-back-bytes=20M", - //"--no-input-terminal", - //"--no-osc", - "--profile=gpu-hq", - "--vo=gpu", - "--hwdec=auto", + args.insert(args.end(), { + "mpv", "--keep-open=yes", input_ipc_server_arg.c_str(), "--no-resume-playback", - /*"--vo=gpu", "--hwdec=auto",*/ - wid_arg.c_str(), "--", path, nullptr }); + wid_arg.c_str() + }); + + if(!use_system_mpv_config) { + args.insert(args.end(), { + "--no-config", "--demuxer-max-bytes=40M", "--demuxer-max-back-bytes=20M", + "--profile=gpu-hq", + "--vo=gpu", + "--hwdec=auto" + }); + } + + args.insert(args.end(), { "--", path, nullptr }); + if(exec_program_async(args.data(), &video_process_id) != 0) return Error::FAIL_TO_LAUNCH_PROCESS; -- cgit v1.2.3