From 01bcd7c89af37a8ff031cf5b7daad77e99436ffc Mon Sep 17 00:00:00 2001 From: jvech Date: Thu, 12 Dec 2024 20:22:36 -0500 Subject: init: initial commit --- mpv-ipc-client.sh | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100755 mpv-ipc-client.sh (limited to 'mpv-ipc-client.sh') 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] [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 -- cgit v1.2.3-70-g09d2