mpv: route casting through a lua script

this lets me use `subcprocess` instead of `run`, and so the command terminate alongside mpv
This commit is contained in:
2024-03-12 05:01:09 +00:00
parent 56a2c4e49f
commit 01fa9919fd
3 changed files with 35 additions and 6 deletions

View File

@@ -139,6 +139,7 @@ in
# for `watch_later`
".local/state/mpv"
];
fs.".config/mpv/scripts/sane/main.lua".symlink.target = ./sane-main.lua;
fs.".config/mpv/input.conf".symlink.target = ./input.conf;
fs.".config/mpv/mpv.conf".symlink.target = ./mpv.conf;
fs.".config/mpv/script-opts/osc.conf".symlink.target = ./osc.conf;

View File

@@ -31,9 +31,7 @@ ctrl+s async screenshot #! Utils > Screenshot
alt+i script-binding uosc/keybinds #! Utils > Key bindings
O script-binding uosc/show-in-directory #! Utils > Show in directory
# script-binding uosc/open-config-directory #! Utils > Open config directory
ctrl+r run blast-to-default #! Audiocast
ctrl+t set pause yes; run xdg-terminal-exec go2tv -v "${stream-open-filename}" #! Cast
# set pause yes; run xdg-terminal-exec go2tv -u "${stream-open-filename}" #! Cast (...) > Stream
# set pause yes; run go2tv #! Cast (...) > GUI
# TODO: unify "Cast" and "Cast (stream)" options above.
ctrl+r script-binding sane/blast #! Audiocast
ctrl+t script-binding sane/go2tv-video #! Cast
# script-binding sane/go2tv-stream #! Cast (...) > Stream
# script-binding sane/go2tv-gui #! Cast (...) > GUI

View File

@@ -0,0 +1,30 @@
function invoke_blast()
mp.command_native({
name = "subprocess",
-- TODO: mpv shutdown hangs if not run w/o xdg-terminal-exec??
args = { "xdg-terminal-exec", "blast-to-default" },
})
end
function invoke_go2tv(in_terminal, args)
local full_args = { "go2tv", table.unpack(args) }
if in_terminal then
full_args = { "xdg-terminal-exec", table.unpack(full_args) }
end
mp.commandv("set", "pause", "yes")
mp.command_native({ name = "subprocess", args = full_args })
end
function invoke_go2tv_on_open_file(mode)
local path = mp.get_property("stream-open-filename");
return invoke_go2tv(true, { mode, path })
end
mp.add_key_binding(nil, "blast", invoke_blast)
mp.add_key_binding(nil, 'go2tv-gui', function() invoke_go2tv(false, {}) end)
mp.add_key_binding(nil, 'go2tv-video', function() invoke_go2tv_on_open_file("-v") end)
mp.add_key_binding(nil, 'go2tv-stream', function() invoke_go2tv_on_open_file("-s") end)
-- uncomment for debugging:
-- if mpv fails to eval this script (e.g. syntax error), then it will fail to quit on launch
-- mp.command('quit')