Shell script for internet radio


I’ve been feeling nostalgic for a holiday I took last year to New Mexico in the USA. We spent a lot of time listening to country radio stations and driving through the beautiful scenery. While I am confined to home I thought it would be nice to listen to those radio stations again, but I was finding it laborious to listen to the radio through my web browser.

Most internet radio streams have a URL, which can be scraped usually by looking at the HTML of the webpage, or rarely if the radio provider is feeling public spirited, in plain text on the streaming page. These URLs are mostly readable by VLC if they are .mp3, .ogg, m3u, .pls and probably many more. The backend of VLC’s streaming capabilities is an in-built plugin called Icecast, previously Shoutcast. I made a simple text file of these URLs along with the names of the stations:,Big I 107.9 Albuquerque New Country,BBC Radio 1,BBC Radio 4 LW

Then I wrote a shell script which uses <code>fzf</code> to neatly display the radio station names, then uses sed and grep to send the URL to the ncurses version of VLC, which on macOS at least is stored in /Applications/ -I ncurses when VLC is installed using Homebrew.



sel=$(sed 's/^.*,//' ${stations} | fzf)

url=$(grep "${sel}" ${stations} | sed 's/,.*$//')

vlc "${url}"

Update 2021-04-18

The BBC changed their radio streaming URLs which prompted me to also change how this script worked a bit. The radio streaming URLs are now stored in a .pls file, which makes it more compatible with other music players. I’ve included the full .pls file here because these URLs are hard to come by online:


Title1=BBC Radio 4 FM

Title2=BBC Radio 4 LW - non UK

Title3=BBC Radio 6

Title4=BBC Radio London

Title5=BBC World Service



Title9=BBC Radio Scotland


The script looks like this:

#!/usr/bin/env sh 


station=$(grep '^Title' ${rfile} | sed 's/^Title\([0-9]\+\)=\(.*\)/\1 - \2/' | fzf | sed 's/\(^[0-9]\+\).*/\1/')

url=$(grep "File${station}=" $rfile | sed 's/.*=//')

/Applications/ -I rc --no-color $url

Update 2021-06-03

I was getting annoyed having to quit out of FZF and relaunch the script every time I wanted to change the radio station, so I re-wrote it to use mpv, using the --bind flag in fzf to run a never-ending loop. I tried to do similar using VLC, but it kept quitting back to FZF immediately, rather than keeping VLC open until I wanted to quit.

#!/usr/bin/env sh


grep '^Title' ${rfile} |\
	sed 's/^Title\([0-9]\+\)=\(.*\)/\1 - \2/' |\
	fzf --bind="enter:execute;echo {} | sed 's/\(^[0-9]\+\).*/\1/' | 
	sed 's/\(.*\)/File\1=/' |
	grep -f - ${rfile} |
	sed 's/.*=//' |
	mpv --playlist=- ;"