Skip to content

Instantly share code, notes, and snippets.

@rzwitserloot
Created October 15, 2009 03:28
Show Gist options
  • Save rzwitserloot/210643 to your computer and use it in GitHub Desktop.
Save rzwitserloot/210643 to your computer and use it in GitHub Desktop.
This script will play radio and should work on macs and linux computers if you have VLC installed. Better than iTunes, in that it works with more stations, and doesn't clutter your media list.
#!/bin/bash
# author: Reinier Zwitserloot
# this script is in the public domain. I relinquish all rights.
# source: http://gist.github.com/210643
# Plays various radio channels, using VLC. Run me from a terminal to see radio station options.
# If your radio skips a lot, you need to suid 'renice'. If you don't know what that means, don't try it yourself; it has serious security implications.
# For this to work, you need VLC. On debian / ubuntu: apt-get install vnc
# on macs, download VLC and install in /Applications, from here: http://www.videolan.org/vlc/download-macosx.html
# uncomment the next line if this script can't find your VLC, and point it to the vlc binary.
#VLC_LOCATION=~/VLC
function getVLCid {
PID=`ps auxww | grep VLC | grep -v grep |awk '{ print $2 }'`
}
function findVLC {
if [ "$HOME" == "" ]; then
HOME=`echo ~`
fi
LIKELY_VLC_LOCATIONS="bin/VLC usr/bin/VLC bin/vlc usr/bin/vlc bin/svlc usr/bin/svlc Applications/VLC.app/Contents/MacOS/VLC bin/VLC.app/Contents/MacOS/VLC"
for LIKELY in $LIKELY_VLC_LOCATIONS; do
if [ "$VLC_LOCATION" == "" ]; then
if [ -x "$HOME/$LIKELY" ]; then
VLC_LOCATION="$HOME/$LIKELY"
exit
fi
if [ -x "/$LIKELY" ]; then
VLC_LOCATION="/$LIKELY"
exit
fi
fi
done
}
function getStatus {
getVLCid
if [ "$PID" != "" ]; then
PLAYING=`ps auxwwl $PID |grep -Eo "\-\-video-title .*" |grep -Eo " .*"`
echo "Playing:$PLAYING"
else
echo "Not playing anything"
fi
exit
}
case "$1" in
"off")
OPENTGT=""
;;
"pid")
getVLCid
if [ "$PID" != "" ]; then
echo $PID
exit 0
else
exit 1
fi
;;
"playing")
getStatus
exit 0
;;
"status")
getStatus
exit 0
;;
"title")
getStatus
exit 0
;;
"arrow")
OPENTGT="http://81.23.251.55/ArrowAudio02"
TITLE="Arrow Classic Rock"
;;
"slam")
OPENTGT="http://stream03.slamfm.trueserver.nl:8080/slamfm";
TITLE="Slam! FM"
;;
"slay")
OPENTGT="http://relay1.slayradio.org:8000/"
TITLE="Slay Radio (c64 remixes)"
;;
"ost")
echo "[playlist]" > /tmp/radio.pls
echo "numberofentries=1" >> /tmp/radio.pls
echo "File1=http://hd.streamingsoundtracks.com:80" >> /tmp/radio.pls
echo "Title1=StreamingSoundtracks.com 128k MP3" >> /tmp/radio.pls
OPENTGT="/tmp/radio.pls"
TITLE="StreamingSoundtracks.com"
;;
"nl1")
OPENTGT="http://shoutcast2.omroep.nl:8100/"
TITLE="Dutch State Radio 1"
;;
"stubru")
OPENTGT="http://mp3.streampower.be/stubru-high"
TITLE="Studio Brussel"
;;
"538")
OPENTGT="http://81.173.117.103/radio538"
TITLE="Radio 538"
;;
"di")
case "$2" in
"vocaltrance")
OPENTGT="http://scfire-ntc-aa06.stream.aol.com:80/stream/1065"
TITLE="di.fm Vocal Trance channel"
;;
"eurodance")
OPENTGT="http://scfire-ntc-aa01.stream.aol.com:80/stream/1024"
TITLE="di.fm Eurodance channel"
;;
"electro")
OPENTGT="http://scfire-mtc-aa02.stream.aol.com:80/stream/1025"
TITLE="di.fm Electro channel"
;;
"club")
OPENTGT="http://72.26.204.18:6344"
TITLE="di.fm club channel"
;;
"psychill")
OPENTGT="http://72.26.204.18:6314"
TITLE="di.fm Psy Chill channel"
;;
"techhouse")
OPENTGT="http://72.26.204.18:6354"
TITLE="di.fm TechHouse channel"
;;
"trance")
OPENTGT="http://scfire-mtc-aa06.stream.aol.com:80/stream/1003"
TITLE="di.fm Trance channel"
;;
"techo")
OPENTGT="http://209.225.189.112:8000"
TITLE="di.fm Techno channel"
;;
"classic")
OPENTGT="http://72.26.204.18:6324"
TITLE="di.fm Classic Eurodance channel"
;;
"chill")
OPENTGT="http://72.26.204.18:6334"
TITLE="di.fm Chillout Dreams channel"
;;
*)
echo "Unknown di.fm channel. Try typing 'radio' without any parameters for a full list."
exit 1
;;
esac
;;
"url")
OPENTGT="$2"
TITLE="Custom URL: $2"
;;
"")
echo "off - turns off the radio"
echo "pid - Prints the PID of the current radio process, if its on."
echo "playing - (aliases: status, title): Prints the currently playing radio station, if any."
echo "arrow - Arrow Classic Rock"
echo "slam - Slam! FM"
echo "slay - Slay Radio (c64 remixes)"
echo "ost - StreamingSoundtracks.com"
echo "nl1 - Dutch state radio 1"
echo "stubru - Studio Brussel"
echo "538 - Radio 538"
echo "url - specify a custom URL as the second parameter"
echo "di vocaltrance - di.fm Vocal Trance channel"
echo "di eurodance - di.fm Eurodance channel"
echo "di electro - di.fm Electronic channel"
echo "di club - di.fm Club House channel"
echo "di psychill - di.fm Psy Chill channel"
echo "di techhouse - di.fm Techno House channel"
echo "di trance - di.fm Trance channel"
echo "di techno - di.fm Techno channel"
echo "di classic - di.fm Classic Eurodance channel"
echo "di chill - di.fm Chillout Dreams channel"
exit 0
;;
*)
echo "Unknown radio station. Run 'radio' without any parameters to see a list of valid radio stations."
exit 1
;;
esac
getVLCid
if [ "$PID" != "" ]; then
#For some reason we need kill -9 ; VLC will, at random, ignore SIGTERM. I have no idea why. Very unfortunate.
kill -9 $PID
fi
if [ "$OPENTGT" != "" ]; then
pushd /tmp >/dev/null 2>&1
nohup /Applications/VLC.app/Contents/MacOS/VLC --intf=dummy "$OPENTGT" --video-title "$TITLE" 1>/dev/null 2>&1 &
popd >/dev/null 2>&1
getVLCid
#renice only works if you suid renice. Without it, you'll notice some skips when your system is very busy, unfortunately.
renice -5 -p $PID >/dev/null 2>&1
echo "Playing: $TITLE"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment