Published on: 2022-08-11

Play SomaFM from shell

Simple shell alias to play your favorite internet radio.

Here is a simple shell script that allows you to simply play SomaFM stations from the command line. If you don't choose a station, it will automatically pick one at random.

It will also check if a 256k stream is available and play that instead of the standard 128k.

Requirements:

  • mpv
  • curl

Usage:

$ soma --list         # print all stations
$ soma <STATION_NAME> # play particular station
$ soma                # play a random station

To use it, put this in your ~/.bashrc or ~/.zshrc file:

function soma {
    if [ -z ${1+x} ]; then
        radio=$(shuf -n 1 $HOME/dotfiles/soma-radios);
    else
        radio="${1}"
    fi
    if [ "$radio" = "--list" ]; then
        cat $HOME/dotfiles/soma-radios;
        return;
    fi;
    url="https://somafm.com/$radio.pls"
    url256="https://somafm.com/${radio}256.pls"
    if curl --head --silent --fail $url256 > /dev/null 2>&1; then
        mpv $url256
    else
        mpv $url
    fi
}

And also put the list of stations in $HOME/dotfiles/soma-radios.

7soul
beatblender
bootliquor
brfm
cliqhop
covers
darkzone
deepspaceone
defcon
digitalis
dronezone
dubstep
fluid
folkfwd
groovesalad
gsclassic
illstreet
indiepop
live
lush
metal
missioncontrol
n5md
poptron
reggae
scanner
secretagent
seventies
sf1033
sonicuniverse
spacestation
specials
suburbsofgoa
synphaera
thetrip
thistle
u80s
vaporwaves

Do not save the file with a trailing newline – otherwise you might play the radio station "empty string".

Don't forget to support SomaFM!