aboutsummaryrefslogtreecommitdiff
path: root/mpv-ipc-client.sh
diff options
context:
space:
mode:
authorjvech <jmvalenciae@unal.edu.co>2024-12-12 20:22:36 -0500
committerjvech <jmvalenciae@unal.edu.co>2024-12-12 20:22:36 -0500
commit01bcd7c89af37a8ff031cf5b7daad77e99436ffc (patch)
tree18232f308d352ef05d8b0157e2af681c1eaf3015 /mpv-ipc-client.sh
init: initial commitHEADmain
Diffstat (limited to 'mpv-ipc-client.sh')
-rwxr-xr-xmpv-ipc-client.sh80
1 files changed, 80 insertions, 0 deletions
diff --git a/mpv-ipc-client.sh b/mpv-ipc-client.sh
new file mode 100755
index 0000000..e7fc188
--- /dev/null
+++ b/mpv-ipc-client.sh
@@ -0,0 +1,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
Feel free to download, copy and edit any repo