blob: e7fc188c3aff28dce6083bc6b5573cabcd77c9e0 (
plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
#!/usr/bin/sh
TEMP=$(getopt -o 'hs:' -l "help,socket:" -- "$@")
if [ $? -ne 0 ]; then
echo 'Terminating...' >&2
exit 1
fi
eval set -- "$TEMP"
unset TEMP
SOCKET_FILE="/tmp/mpv-audio-server-$USER.socket"
usage() {
echo "Usage: $(basename $0) [-h] [-s SOCKET] <cmd> [ARGS...]"
echo "Options:"
echo " -h, --help Show this message"
echo " -s, --socket=SOCKET Point to socket file [default: $SOCKET_FILE]"
exit $1
}
while true; do
case "$1" in
'-h'|'--help')
usage 0
break
;;
'-s'|'--socket')
SOCKET_FILE=$2
shift 2
break
;;
'--')
shift
break
;;
*)
usage 1
break
;;
esac
done
if [ $# -eq 0 ]; then
usage 1
fi
cmd="$1"
case $cmd in
"loadfile")
query="$(echo $2 | tr ' ' +)"
ipc_cmd='{ "command": ['
ipc_cmd="$ipc_cmd\"$cmd\", \"ytdl://ytsearch:$query\""
shift 2
for arg in $@; do
ipc_cmd="$ipc_cmd, \"$arg\""
done
ipc_cmd="$ipc_cmd] }"
echo $ipc_cmd | socat - $SOCKET_FILE
exit 0
;;
*)
ipc_cmd='{ "command": ['
ipc_cmd="$ipc_cmd\"$cmd\""
shift 1
for arg in $@; do
case $arg in
true|false|[0-9]+|[0-9]*.[0-9]+)
ipc_cmd="$ipc_cmd, $arg"
;;
*)
ipc_cmd="$ipc_cmd, \"$arg\""
;;
esac
done
ipc_cmd="$ipc_cmd] }"
echo $ipc_cmd | socat - $SOCKET_FILE
exit 0
;;
esac
W_MENU_LINES=10
|