-
Notifications
You must be signed in to change notification settings - Fork 1
/
mpvctl
executable file
·41 lines (34 loc) · 947 Bytes
/
mpvctl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/sh -e
help() {
cat - >&2 <<EOF
mpvctl - control mpv via sockets
mpvctl [next|previous|play-pause|play|pause|stop|{JSON...}]
Requires socat and input-ipc-server=/tmp/mpvctl in your mpv.conf OR use
my multisocket.lua script from my dotfiles if you want to control
multiple mpv processes.
EOF
}
mpv_send() {
for socket in /tmp/mpvctl*; do {
[ -S "$socket" ]
socat - "$socket" <<-EOF
$1
EOF
} || continue
done
}
if ! command -v socat > /dev/null; then
echo 'socat must be installed' >&2
exit 1
fi
case "$1" in
'{'*) mpv_send "$1";;
next) mpv_send '{"command": ["playlist-next"]}';;
previous) mpv_send '{"command": ["playlist-prev"]}';;
play-pause) mpv_send '{"command": ["cycle", "pause"]}';;
play) mpv_send '{"command": ["play"]}';;
pause) mpv_send '{"command": ["pause"]}';;
stop) mpv_send '{"command": ["quit"]}';;
--help|-h) help; exit 0;;
*) help; exit 1;;
esac