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
|
#!/bin/bash -e
#
# playstream -- smart handler for m3u/pls files for mpd
# version 2006.03.15.0005
#
# (c) 2006 martin f. krafft <playstream@pobox.madduck.net>
# Released under the terms of the artistic licence.
#
### begin host configuration
# do whatever you want here. note that my default below automatically
# decides where to play the music based on the ARP cache. it ignores
# existing MPD_HOST values. i am sure you know what to do if you don't
# like that.
#
export MPD_HOST=localhost
if ip neigh | grep -q '192\.168\.14\.1 .\+ 08:00:46:b1:2d:ee REACHABLE'; then
MPD_HOST="XXXXXXXXX@yy.cccccc.net"
fi
### end host configuration
declare -a lists
unset verbose
LONGOPTS=replace,append,queue,verbose
SHORTOPTS=raqv
ME=${0##*/}
for opt in $(getopt -u -n $ME -l $LONGOPTS -o $SHORTOPTS -- $@); do
case $opt in
-r) # replace list immediately
mpc clear;;
-a) # append to list
:;;
-q) # append, but queue next
mpc crop;;
-v) # verbose
verbose=1;;
--) :;;
*.m3u|*.pls)
if [ -r $opt ]; then
lists=(${lists[@]} $opt)
else
echo "$ME: unreadable file -- $opt" >&2
exit 2
fi;;
*)
echo "$ME: invalid argument -- $opt" >&2
exit 1;;
esac
done
if [ -z "${lists[@]}" ]; then
[ -n "$verbose" ] && echo $ME: no input files. >&2
exit 0
fi
if [ -n "$verbose" ]; then
echo "I: playing on host ${MPD_HOST#*@}:"
for i in ${lists[@]}; do
echo "I: $i"
done
fi
# pls files have annoying File[[:digit:]]* prefixes
# m3u files are fine, mpc ignores commented lines
# thus, the following takes care of all:
sed -e 's/^File[[:digit:]]*=//' ${lists[@]} | mpc add >/dev/null
mpc play # doesn't do anything if already playing
exit 0
|