Created
April 24, 2019 07:55
-
-
Save kmwenja/2c79fda75b72e0e51cf2cd84bf6c9153 to your computer and use it in GitHub Desktop.
MPV Radio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# initialize a fifo file to control what station mpv is playing | |
MPVFIFO=$HOME/.radio/mpv | |
if [[ ! -p $MPVFIFO ]]; then | |
mkfifo $MPVFIFO | |
fi | |
# select the radio station to start playing | |
STATION_NAME=$(cat .radio/stations | awk -F ',' '{print $1}' | dmenu -p 'Choose station:') | |
STATION_URL=$(grep "$STATION_NAME" .radio/stations | awk -F ',' '{print $2}') | |
# if the radio mpv is not running, start it otherwise use the existing mpv | |
PIDFILE=$HOME/.radio/mpv.pid | |
PID=$(test -e $PIDFILE && cat $PIDFILE || echo -1) | |
if test -e /proc/$PID/cmdline | |
then | |
# tell the existing mpv to start playing the selected station instead | |
printf "%s\n" "loadfile \"$STATION_URL\" replace" > $MPVFIFO | |
else | |
# start a new mpv instead playing the selected station | |
mpv --quiet --input-file=$HOME/.radio/mpv --input-ipc-server=$HOME/.radio/mpv.sock "$STATION_URL" >> $HOME/.radio/$(date --rfc-3339=date).log & | |
echo $! > $PIDFILE | |
fi | |
notify-send "Playing: $STATION_NAME" | |
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PIDFILE=$HOME/.radio/mpv.pid | |
test -e $PIDFILE && kill -15 $(cat $PIDFILE) && notify-send "Radio stopped" || notify "Radio is not on" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment