Merge pull request #80 from AlexanderPavlenko/master
[shell-fm.git] / scripts / shell-fm-tune.sh
blob90d0825d7c56d5952a302b6cee9ae9a8c01bb23d
1 #!/bin/bash
2 # Published under the terms of the GNU General Public License (GPL).
4 extract ()
6 KEY="$1"
7 VALUE="$(
8 sed -e "s/^$KEY\s*=\s*//" <<<"`
9 grep -oE "^$KEY[ ]*=[ ]*[^ ]+" $HOME/.shell-fm/shell-fm.rc \
10 | head -n 1
13 echo "$VALUE"
17 if [ $# -eq 0 ]; then
18 echo "Usage: shell-fm-tune lastfm://radio_url [HOST [PORT]]"
19 exit -1
23 RADIO="$1"
25 IP=
26 PORT=
27 CMD=
29 if [ $# -gt 1 ]; then
30 IP="$2"
31 if [ $# -gt 2 ]; then PORT="$3"; fi
32 elif [ -r "$HOME/.shell-fm/shell-fm.rc" ]; then
33 IP="`extract "bind"`"
34 PORT="`extract "port"`"
38 if [ -n "`which nc 2>/dev/null`" ]; then
39 CMD="nc"
40 elif [ -n "`which telnet`" ]; then
41 CMD="telnet"
42 else
43 echo "Netcat or telnet must be installed!"
44 exit -1
47 [ -z "$IP" ] && IP="127.0.0.1"
48 [ -z "$PORT" ] && PORT="54311"
50 echo "play $RADIO" | "$CMD" "$IP" "$PORT" >/dev/null 2>&1