#!/bin/bash # file name: inet-radio.sh # Pete Nesbitt, October 2014 (pete at linux1 dot ca) # script to start mplayer and stream from a Internet Radio site. # works at the command line or via a startup script (possibly on a headless box). # (script used in my Internet Radio Black Box Project) ##################################################################### # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . ##################################################################### # REQUIRES (in addition to working sound & speakers/headphones:) # mplayer -from mplayerhq.hu (fedora rpm's available from rpmfusion.org) # # HOW TO GET STREAM URL # go to web site streaming page (with the "Player" on it), # view the page source and just search for an HREF string ending # with a supported file type (asx, pls, m3u etc) # example (using http://www.toddfans.com/listen-live.html as the site with embeded web player) # 1) open html code in web browser, usually 'right click' select "View Page Source" # 2) look for a "HREF" or "href" ending with a with .asx, .pls, or .m3u # HREF="http://s01.whooshserver.net/streampanel/tunein.php/alcannon/playlist.asx" # use the URL between the quotes for the value of URL in the variables section # # so desired variable setting is # URL="http://s01.whooshserver.net/streampanel/tunein.php/alcannon/playlist.asx" # # I tried to test from live365 but could not figure out the stream URL. The sites I used are # all single source, not a directory of many stations like live365 and similar sites. # Here is a list of a few sites I tried. Just plug them in as the 'URL' var below. # (the script plays whichever station is in the URL variable) #STATIONS: # http://s01.whooshserver.net/streampanel/tunein.php/alcannon/playlist.asx ## Todd Rundgren Radio (toddfans.com) # http://playerservices.streamtheworld.com/pls/CBC_R1_VIC_H.pls ## CBC Radio 1, (talk) Victoria Canada # http://playerservices.streamtheworld.com/pls/CBC_R2_VCR_H.pls ## CBC Radio 2, (Classical) Vancouver Canada # http://www.cjsf.ca/listen-hq.m3u ## Simon Fraser University, Greater Vancouver, Canada # Also check out http://www.canadianwebradio.com/ or similar for easy stream URL's. # On canadianwebradio.com, you can just mouse down the 'Listen Live' column looking for url's ending in asx, pls, or m3u. # example mplayer command line: # mplayer -cache 512 -cache-min 50 -playlist http://s01.whooshserver.net/streampanel/tunein.php/alcannon/playlist.asx # troubleshooting: # this worked fine for me but if it fails: # 1) at a command line try the mplayer command shown above, it should work or give a meaningful error # 2) try with and without the '-playlist' argument (if it works change the 3 insences # of PLAY in the "#check vars" section below). # 3) aside from the script, if mplayer is not producing any sound it may be PulseAudio or ALSA subsystems. # On my main test box I had to start mplayer with a "-ao alsa," to force it to try ALSA before Pulse. ##################################################################### # variables NAME="Internet Radio Player" MPLAYER="`which mplayer`" MPCACHE="384" # in KB (empty to use mplayer defaults of 320) MPCACHEMIN="50" # percent cache should fill before starting player (leave empty to use mplayer default 19%) # preloading cache delays start time but help if bandwidth is limited # This should work for everyone who likes music, however the STATIONS section above has other known-good URL's (stations). URL="http://cp.usa7.fastcast4u.com:2199/tunein/alcann00.asx" #check vars #check for mplayer which mplayer &> /dev/null MPLAY_VAL=$? if [ ${MPLAY_VAL} -ne 0 ];then echo "FATAL ERROR --Missing mplayer binary-- exiting ${NAME}" exit 1 else PLAY="${MPLAYER} -cache ${MPCACHE} -cache-min ${MPCACHEMIN} -playlist ${URL}" fi if [ -z "${MPCACHE}" ];then #MPCACHE empty, drop MPCACHE & MPCACHEMIN from cmd PLAY="${MPLAYER} -playlist ${URL}" elif [ -n "${MPCACHE}" ] && [ -z "${MPCACHEMIN}" ];then #MPCACHE has a numeric value but MPCACHEMIN empty, then drop MPCACHEMIN from cmd PLAY="${MPLAYER} -cache ${MPCACHE} -playlist ${URL}" fi ## start main while : # infinate loop, restarts mplayer if it exits due to broken pipe etc do pidof mplayer &> /dev/null PID_OK=$? if [ ${PID_OK} -ne 0 ];then sleep 5 $PLAY fi done # eof