A short while ago I made a little quality of life script that I can use to control the web radio I listen to while on my computer.

It uses dmenu to select a radio station, then plays it through mpv. It will stop a running instance when selecting a different station. I mapped Super+F3 to running the script so I can easily change radio stations with it.

The radio stations are put in a .m3u file which must be specially formatted for the script. Every radio station link should be preceded by a comment containing the radio station name. The names will be sent to dmenu to select the station. Then using grep it will grab the URL and run it. An edited version of the script I use is below:

# use dmenu to choose radio station and get URL
choice="$(grep '^#' ~/Music/radio.m3u | sed 's/^# //' | dmenu -i -l 20 -b)"
if [ "$?" -ne 0 ]; then exit 1; fi # quit if dmenu "fails" (by pressing escape)
url="$(grep -FxA 1 "# $choice" ~/Music/radio.m3u | tail -1)"

# kill running tradio instance
pkill -f 'mpv --title=TRADIO'

# play URL through mpv
mpv --title=TRADIO --force-window=yes "$url"

The above script is edited because mine also first mounts a network share to get the radio.m3u file (I put it on a shared directory over sshfs so I can share it between computers).

Here an example of the radio.m3u file format, containing links to Dutch radio 1, 2, 3 and 4:

# Radio 1
https://icecast.omroep.nl/radio1-bb-aac
# Radio 2
https://icecast.omroep.nl/radio2-bb-aac
# 3FM
https://icecast.omroep.nl/3fm-bb-aac
# Radio 4
https://icecast.omroep.nl/radio4-bb-aac

Screenshot of the dmenu selection with these radio stations:

screenshot of dmenu running with radio stations from example radio.m3u, from the tradio script.

Screenshot of mpv streaming a radio station:

screenshot of mpv playing the stream NPO Radio 4 - NTR Opera Live

Just a little script I wanted to show off. Happy hacking!