add mpv_websocket
This commit is contained in:
parent
829141ccd9
commit
7904708a42
2
ModernZ
2
ModernZ
@ -1 +1 @@
|
|||||||
Subproject commit 04bd74082d47587eae049460c58d9706f8d28b1d
|
Subproject commit 2d5537aa72e4ddf4b68ca6cc4dfa1ce00cbec370
|
BIN
mpv_websocket
Executable file
BIN
mpv_websocket
Executable file
Binary file not shown.
@ -17,7 +17,7 @@ save_full_queue=ctrl+S
|
|||||||
remove_from_queue=ctrl+x
|
remove_from_queue=ctrl+x
|
||||||
play_selected_video=ctrl+ENTER
|
play_selected_video=ctrl+ENTER
|
||||||
browser=firefox
|
browser=firefox
|
||||||
clipboard_command=wl-paste -p
|
clipboard_command=wl-paste
|
||||||
cursor_icon=➤
|
cursor_icon=➤
|
||||||
display_limit=10
|
display_limit=10
|
||||||
download_directory=~/videos/YouTube
|
download_directory=~/videos/YouTube
|
||||||
@ -30,6 +30,6 @@ menu_timeout=5
|
|||||||
show_errors=yes
|
show_errors=yes
|
||||||
ytdlp_file_format=mp4
|
ytdlp_file_format=mp4
|
||||||
ytdlp_output_template=%(uploader)s/%(title)s.%(ext)s
|
ytdlp_output_template=%(uploader)s/%(title)s.%(ext)s
|
||||||
use_history_db=yes
|
use_history_db=no
|
||||||
backend_host=http://localhost
|
backend_host=http://localhost
|
||||||
backend_port=42069
|
backend_port=42069
|
||||||
|
83
scripts/run_websocket_server.lua
Normal file
83
scripts/run_websocket_server.lua
Normal file
@ -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()
|
Loading…
x
Reference in New Issue
Block a user