#!/bin/sh # mpdsrvp # # Serve a MPD instance on a different port already in a partition # This "adds" partition support for mpd clients that don't support it. # # ~jmjl : "${mpd_srv_addr:="127.0.0.1"}" : "${mpd_srv_port:="6600"}" mpm() { printf '%s\n' "$1" | timeout 0.15 nc "$mpd_srv_addr" "$mpd_srv_port" } [ -z "$ca95505c_baa3_4c12_95b3_552426a8aea5_mpdsrvp" ] && { [ "$#" -lt "1" ] && { printf 'mpdsrvp [add/del/list/(move )] (,bind=)\n'; exit 1; } case "$1" in "add") mpm "newpartition $2";; "del") mpm "delpartition $2";; "list") mpm "listpartitions";; "move") mpm "partition $2 moveoutput $3";; *) export ca95505c_baa3_4c12_95b3_552426a8aea5_mpdsrvp="$1" socat TCP-L:"$2",reuseaddr,fork,nodelay SYSTEM:"$0";; esac exit; } { printf 'partition %s\n' "$ca95505c_baa3_4c12_95b3_552426a8aea5_mpdsrvp"; cat; } |\ nc "$mpd_srv_addr" "$mpd_srv_port" |\ sed --unbuffered '2d'