-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfip
executable file
·49 lines (40 loc) · 1.47 KB
/
fip
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
#!/usr/bin/env bash
# Global script variables, change here to customise
MYRADIO='black'
STREAMNAME='Fip Radio'
STREAMURL='http://chai5she.cdn.dvmr.fr/fip-midfi.mp3'
# Check for mpc
[ ! -x "$(which mpc)" ] && echo 'Program "mpc" not found.' >&2 && exit 1
# Use first cmdline parameter or MPD_HOST variable or MYRADIO
HOST=${1:-$MPD_HOST}
HOST=${HOST:-$MYRADIO}
# Use port specified as "host:port" or MPD_PORT variable or "6600"
set - ${HOST/:/' '}
HOST=$1
PORT=${2:-$MPD_PORT}
PORT=${PORT:-'6600'}
# Check if radio hostname can or should be localhost
THISHOST=$(hostname -s)
[ "$HOST" = "$THISHOST" -o "$HOST" = 'me' -o "$HOST" = 'this' ] && HOST='localhost'
# Check if mpd can be reached on host:port
ERR=$(mpc -q -h "$HOST" -p "$PORT" 2>&1)
[ -n "$ERR" ] && echo "Host down or mpd not running on \"$HOST:$PORT\"." >&2 && exit 2
# Save current track in variable OLD, stop playing
OLD=$(mpc -h "$HOST" -p "$PORT" -f '%file%' current)
[ -n "$OLD" ] && mpc -q -h "$HOST" -p "$PORT" stop &> /dev/null
# Status
echo -n "$STREAMNAME "
[ "$HOST" != 'localhost' ] && echo -n "on \"$HOST\" "
# Start stream if it wasn't playing before
if [ "$OLD" = "$STREAMURL" ]; then
# It was playing before but now it's off
echo 'off'
else
# Radio was off or playing something else
mpc -q -h "$HOST" -p "$PORT" clear &> /dev/null
mpc -q -h "$HOST" -p "$PORT" add "$STREAMURL" &> /dev/null
mpc -q -h "$HOST" -p "$PORT" play &> /dev/null
# Display volume
mpc -h "$HOST" -p "$PORT" volume
fi
exit 0