aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md61
-rw-r--r--mpv-audio-server.service7
-rwxr-xr-xmpv-ipc-client.sh80
3 files changed, 148 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..d89676e
--- /dev/null
+++ b/README.md
@@ -0,0 +1,61 @@
+# Simple mpv audio ipc server service to play your songs
+
+The client is designed to be a cli wrapper of [mpv ipc
+reference](https://mpv.io/manual/master/#json-ipc)
+
+## Requirements
+* mpv
+* yt-dlp
+* socat
+* systemd system
+
+## Installation
+
+To enable the service run:
+```
+sudo install -Dm 644 mpv-audio-server.service /usr/lib/systemd/user
+systemctl --user enable --now mpv-audio-server
+```
+
+Install the script ipc client with:
+```
+install -Dm 755 mpv-ipc-client.sh ~/.local/bin
+```
+
+or make your own script using [mpv json-ipc reference](https://mpv.io/manual/master/#json-ipc)
+
+## Usage
+
+```
+Usage: mpv-ipc-client.sh [-h] [-s SOCKET] <cmd> [ARGS...]
+Options:
+ -h, --help Show this message
+ -s, --socket=SOCKET Point to socket file [default: /tmp/mpv-audio-server-vech.socket]
+```
+
+Play a song, it is important enclose song query in quotation marks
+```
+mpv-ipc-client.sh loadfile "master of puppets"
+```
+
+Append a song, to the playlist
+```
+mpv-ipc-client.sh loadfile "master of puppets" append-play
+```
+
+toggle between pause or play
+```
+mpv-ipc-client.sh cycle pause
+```
+
+get playlist:
+```
+mpv-ipc-client.sh get_property playlist
+```
+
+## See Also
+
+To checkout all properties and commands availables run `mpv --list-properties`
+and `mpv --input-cmdlist` respectively
+
+Find more info at [mpv json-ipc reference](https://mpv.io/manual/master/#json-ipc)
diff --git a/mpv-audio-server.service b/mpv-audio-server.service
new file mode 100644
index 0000000..d7defa8
--- /dev/null
+++ b/mpv-audio-server.service
@@ -0,0 +1,7 @@
+[Unit]
+Description=Mpv audio server
+[Service]
+Type=exec
+ExecStart=/usr/bin/mpv --really-quiet --ytdl-format=bestaudio --idle=yes --input-ipc-server=/tmp/mpv-audio-server-%u.socket
+[Install]
+WantedBy=default.target
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