diff --git a/ModernZ b/ModernZ index 04bd740..2d5537a 160000 --- a/ModernZ +++ b/ModernZ @@ -1 +1 @@ -Subproject commit 04bd74082d47587eae049460c58d9706f8d28b1d +Subproject commit 2d5537aa72e4ddf4b68ca6cc4dfa1ce00cbec370 diff --git a/mpv_websocket b/mpv_websocket new file mode 100755 index 0000000..2f52bb4 Binary files /dev/null and b/mpv_websocket differ diff --git a/script-opts/mpv-youtube-queue.conf b/script-opts/mpv-youtube-queue.conf index 9f19831..222acc0 100644 --- a/script-opts/mpv-youtube-queue.conf +++ b/script-opts/mpv-youtube-queue.conf @@ -17,7 +17,7 @@ save_full_queue=ctrl+S remove_from_queue=ctrl+x play_selected_video=ctrl+ENTER browser=firefox -clipboard_command=wl-paste -p +clipboard_command=wl-paste cursor_icon=➤ display_limit=10 download_directory=~/videos/YouTube @@ -30,6 +30,6 @@ menu_timeout=5 show_errors=yes ytdlp_file_format=mp4 ytdlp_output_template=%(uploader)s/%(title)s.%(ext)s -use_history_db=yes +use_history_db=no backend_host=http://localhost backend_port=42069 diff --git a/scripts/run_websocket_server.lua b/scripts/run_websocket_server.lua new file mode 100644 index 0000000..2f7e07e --- /dev/null +++ b/scripts/run_websocket_server.lua @@ -0,0 +1,83 @@ +-- mpv_websocket +-- https://github.com/kuroahna/mpv_websocket + +local utils = require("mp.utils") + +local platform = mp.get_property_native("platform") + +local config_file_path = mp.find_config_file("mpv.conf") +local config_folder_path, config_file = utils.split_path(config_file_path) +local mpv_websocket_path = + utils.join_path(config_folder_path, platform == "windows" and "mpv_websocket.exe" or "mpv_websocket") +local initialised_websocket + +local _, err = utils.file_info(config_file_path) +if err then + error("failed to open mpv config file `" .. config_file_path .. "`") +end + +local _, err = utils.file_info(mpv_websocket_path) +if err then + error("failed to open mpv_websocket") +end + +local function find_mpv_socket(config_file_path) + local file = io.open(config_file_path, "r") + if file == nil then + error("failed to read mpv config file `" .. config_file_path .. "`") + end + + local mpv_socket + for line in file:lines() do + mpv_socket = line:match("^input%-ipc%-server%s*=%s*(%g+)%s*") + if mpv_socket then + break + end + end + + file:close() + + if not mpv_socket then + error("input-ipc-server option does not exist in `" .. config_file_path .. "`") + end + + return mpv_socket +end + +local mpv_socket = find_mpv_socket(config_file_path) +if platform == "windows" then + mpv_socket = "\\\\.\\pipe" .. mpv_socket:gsub("/", "\\") +end + +local function start_websocket() + initialised_websocket = mp.command_native_async({ + name = "subprocess", + playback_only = false, + capture_stdout = true, + capture_stderr = true, + args = { + mpv_websocket_path, + "-m", + mpv_socket, + "-w", + "6677", + }, + }) +end + +local function end_websocket() + mp.abort_async_command(initialised_websocket) + initialised_websocket = nil +end + +local function toggle_websocket() + local paused = mp.get_property_bool("pause") + if initialised_websocket and paused then + end_websocket() + elseif not initialised_websocket and not paused then + start_websocket() + end +end + +mp.register_script_message("togglewebsocket", toggle_websocket) +start_websocket()