BASH SCRIPT to listening internet radio on Librem 5

I made and use this script on my PureOS laptop. Nowadays works almost without changes in Librem 5

I use three files to have a desktop shortcut (internetradio.desktop internetradio.png internetradio.sh)

open gedit or another text editor and write the following and save as internetradio.desktop file:

[Desktop Entry]
Name=Internet Radio
Type=Application
Terminal=True
Icon=/home/purism/.local/share/icons/internetradio.png
Exec=/home/purism/5librem/internetradio.sh
Categories=Utility;

internetradio.desktop file should be in /home/purism/.local/share/applications/

Be sure to put the path were the bash script file will be stored ( i.e. Exec=/myhome/path/internetradio.sh

the bash script file:

#!/bin/bash
# Listen internet radio stations. By Antonio Paternina Alvarez. Press the number/letter of the station on menu. When running press Ctrl-C to stop, SPACEbar to see the menu. To exit menu press the [.] on your keyboard. 
#---------------define variables---------
tit="   Internet Radio" 
line="--------------------"
uno=" 1. ADVenir Bolivia"
dos=" 2. Altiplano AdVenir Bolivia"
tres=" 3. AMANECER VZLA *"
cuat=" 4. FAITH FM BELIZE"
cinc=" 5. GLOBAL FAMILY NETWORK - Guyana"
seis=" 6. La Perla" 
siet=" 7. LA VOZ Internacional VZLA"
ocho=" 8. Los Angeles del valle"
nuev=" 9. MELODIES OF PRAYER-GUAM"
opcA=" A. NT Argentina"
opcB=" B. NT Bolivia"
opcC=" C. NT Brazil"
opcD=" D. NT Chile"
opcE=" E. NT Ecuador"
opcF=" F. NT Paraguay"
opcG=" G. NT Perú"
opcH=" H. NT Uruguay"
opcI=" I. RA España"
opcJ=" J. RADIO SWISS CLASSIC"
opcK=" K. RADIOSOL.ORG"
opcL=" L. Silohradio.com Bogotá"
opcM=" M. Terceiro Anjo BR"
opcN=" N. WTPM 92.9FM"
oFin=" .  Exit"
#---------user defined function----------
show_menu() {
echo -ne "\033];$tit\007" # Set terminal window title
    clear
# echo "$tit"
# echo "$line"
 echo "$uno          $oFin"
 echo "$dos"
 echo "$tres"
 echo "$cuat"
 echo "$cinc"
 echo "$seis"
 echo "$siet"
 echo "$ocho"
 echo "$nuev"
 echo "$opcA"
 echo "$opcB"
 echo "$opcC"
 echo "$opcD"
 echo "$opcE"
 echo "$opcF"
 echo "$opcG"
 echo "$opcH"
 echo "$opcI"
 echo "$opcJ"
 echo "$opcK"
 echo "$opcL"
 echo "$opcM"
 echo "$opcN"
}
read_options() {
# read input from keyboard and take a action. # invoke the uno() when user select 1 from the menu option. #  ffmpeg -i $url -f mp3 -ar 44100 -ac 2 - ab 96000 - | ffplay -i -
    local choice
    while IFS= read -rn1 choice
    do
	show_menu
	case $choice in
	    1) echo -ne "\033];$uno\007"; ffmpeg -i "https://stream.eleden.com/radioadvenir.aac/radioadvenir.aac.stream/chunklist_w663415479.m3u8" -f mp3 -ar 44100 -ac 2 -ab 96000 - | ffplay -nodisp -i - ;;
	    2) echo -ne "\033];$dos\007"; ffmpeg -i "https://stream.eleden.com/altiplano.aac/altiplano.aac.stream/chunklist_w1630781586.m3u8" -f mp3 -ar 44100 -ac 2 -ab 96000 - | ffplay -nodisp -i - ;;
	    3) echo -ne "\033];$tres\007"; ffmpeg -i "https://stream.eleden.com/veamanecer.aac/veamanecer.aac.stream/chunklist_w1395968203.m3u8" -f mp3 -ar 44100 -ac 2 -ab 96000 - | ffplay -nodisp -i - ;;
	    4) echo -ne "\033];$cuat\007"; ffmpeg -i "https://stream.eleden.com/faithfm.aac/faithfm.aac.stream/chunklist_w1908339108.m3u8" -f mp3 -ar 44100 -ac 2 -ab 96000 - | ffplay -nodisp -i -  ;;
	    5) echo -ne "\033];$cinc\007"; ffmpeg -i "https://stream.eleden.com/tgfnradio.aac/tgfnradio.aac.stream/chunklist_w1295062531.m3u8" -f mp3 -ar 44100 -ac 2 -ab 96000 - | ffplay -nodisp -i - ;;
	    6) echo -ne "\033];$seis\007"; ffmpeg -i "https://stream.eleden.com/gcristovienejm.aac/gcristovienejm.aac.stream/chunklist_w540088881.m3u8" -f mp3 -ar 44100 -ac 2 -ab 96000 - | ffplay -nodisp -i - ;;
	    7) echo -ne "\033];$siet\007"; ffmpeg -i "https://stream.eleden.com/lavoz106.aac/lavoz106.aac.stream/chunklist_w308032128.m3u8" -f mp3 -ar 44100 -ac 2 -ab 96000 - | ffplay -nodisp -i - ;;
	    8) echo -ne "\033];$ocho\007"; ffmpeg -i "https://stream.eleden.com/glosangelesdv.aac/glosangelesdv.aac.stream/chunklist_w1013177295.m3u8" -f mp3 -ar 44100 -ac 2 -ab 96000 - | ffplay -nodisp -i - ;;
	    9) echo -ne "\033];$nuev\007"; ffmpeg -i "https://stream.eleden.com/melodiesop.aac/melodiesop.aac.stream/chunklist_w1945295462.m3u8" -f mp3 -ar 44100 -ac 2 -ab 96000 - | ffplay -i -nodisp -i -  ;;
	    a) echo -ne "\033];$opcA\007"; ffmpeg -i "https://stream.live.novotempo.com/radio/smil:rntBuenosAiresAR.smil/chunklist_b128000_slspa.m3u8" -f mp3 -ar 44100 -ac 2 -ab 96000 - | ffplay -nodisp -i - ;;
	    b) echo -ne "\033];$opcB\007"; ffmpeg -i "https://stream.live.novotempo.com/radio/smil:rntCochabambaBO.smil/chunklist_b64000_slspa.m3u8" -f mp3 -ar 44100 -ac 2 -ab 96000 - | ffplay -nodisp -i - ;;
	    c) echo -ne "\033];$opcC\007"; ffmpeg -i "https://stream.live.novotempo.com/radio/smil:radionovotempo.smil/chunklist_b96000_slpor.m3u8" -f mp3 -ar 44100 -ac 2 -ab 96000 - | ffplay -nodisp -i - ;;
	    d) echo -ne "\033];$opcD\007"; ffmpeg -i "https://stream.live.novotempo.com/radio/smil:rntChillanCL.smil/chunklist_b64000_slspa.m3u8" -f mp3 -ar 44100 -ac 2 -ab 96000 - | ffplay -nodisp -i - ;;
	    e) echo -ne "\033];$opcE\007"; ffmpeg -i "https://stream.live.novotempo.com/radio/smil:rntQuitoEC.smil/chunklist_b64000_slspa.m3u8" -f mp3 -ar 44100 -ac 2 -ab 96000 - | ffplay -nodisp -i - ;;
	    f) echo -ne "\033];$opcF\007"; ffmpeg -i "https://stream.live.novotempo.com/radio/smil:radionuevotiempo.smil/playlist.m3u8" -f mp3 -ar 44100 -ac 2 -ab 96000 - | ffplay -nodisp -i - ;;
	    g) echo -ne "\033];$opcG\007"; ffmpeg -i "https://stream.live.novotempo.com/radio/smil:rntLimaPE.smil/chunklist_b128000_slspa.m3u8" -f mp3 -ar 44100 -ac 2 -ab 96000 - | ffplay -nodisp -i - ;;
	    h) echo -ne "\033];$opcH\007"; ffmpeg -i "https://stream.live.novotempo.com/radio/smil:rntMontevideoUY.smil/chunklist_b64000_slspa.m3u8" -f mp3 -ar 44100 -ac 2 -ab 96000 - | ffplay -nodisp -i - ;;
	    i) echo -ne "\033];$opcI\007"; ffmpeg -i "http://n0c.radiojar.com/aesy2chkb?rj-ttl=5&rj-tok=AAABc-Q0lmcABCwhSI7mTJi3fA" -f mp3 -ar 44100 -ac 2 -ab 96000 - | ffplay -nodisp -i - ;;
	    j) echo -ne "\033];$opcJ\007"; ffmpeg -i "https://stream.eleden.com/radioswissc.aac/radioswissc.aac.stream/chunklist_w1239878985.m3u8" -f mp3 -ar 44100 -ac 2 -ab 96000 - | ffplay -nodisp -i - ;;
	    k) echo -ne "\033];$opcK\007"; ffmpeg -i "https://stream.eleden.com/wzol.aac/wzol.aac.stream/chunklist_w1537564109.m3u8" -f mp3 -ar 44100 -ac 2 -ab 96000 - | ffplay -nodisp -i - ;;
	    l) echo -ne "\033];$opcL\007"; ffmpeg -i "http://stream.eleden.com:1935/siloh.aac/siloh.aac.stream/playlist.m3u8" -f mp3 -ar 44100 -ac 2 -ab 96000 - | ffplay -nodisp -i - ;;
	    m) echo -ne "\033];$opcM\007"; ffmpeg -i "https://stream.eleden.com/gterceiroanjo.aac/gterceiroanjo.aac.stream/chunklist_w772186788.m3u8" -f mp3 -ar 44100 -ac 2 -ab 96000 - | ffplay -nodisp -i - ;;
	    n) echo -ne "\033];$opcN\007"; ffmpeg -i "https://stream.eleden.com/wtpm.aac/wtpm.aac.stream/chunklist_w1374238332.m3u8" -f mp3 -ar 44100 -ac 2 -ab 96000 - | ffplay -nodisp -i - ;;
	    .) exit 0 ;;
	    *) echo "Error..." && sleep 1 
	esac	
done
}


# --------------------
#  Step 3. Trap Ctrl+C, Ctrl+Z and quit singles
# ------------------------------
trap '' SIGINT SIGQUIT SIGTSTP

# ------------------------------
#   Step 4. Main Logic - Infinite loop
# ------------------------------
while true
do
    show_menu
    read_options
done

----------------------------------------------

CHOOSE A image for your desktop shorcut and put it in /home/purism/.local/share/icons

Give execution attributes to internetradio.sh with
chmod +x internetradio.sh

That is all. The script will show a menu to choose the internet radio using numbers 1 to 9 and letters A to N. To exit just press the “.” dot

To exit/change to another station running Simple press Ctrl+C then press any key to see the menu again.

the icon i made:
internetradio

Internetradio on the upper right on this screen shot:

the menu to select radio station:

Radio Station NT Paraguay playing

NT Paraguay radio station stop by pressing Ctrl-C

Playing option F. Radio Swiss Classical

6 Likes

I love your choice in music👍 and the script👍
Edit: How do you find the stream url for internet stations? I am trying to put kuyo.com in there but I can’t find the stream url

I inspect the webpage html looking for the streaming link; usually it ends with .aac.stream or .m3u8

It is not easy but it is possible mostly.

1 Like

mpv https://ais-sa1.streamon.fm/7061_24k.aac/playlist.m3u8

But are you sure? I tried to listen to the guy speaking… I can’t. Anyway … if you like it, there you have it.

2 Likes

http://ais-sa1.streamon.fm/7061_24k.aac/playlist.m3u8
I found also.

Nowaday I am listening the man speaking using the link above in VLC. I put the link on Open Network Stream (Ctrl-N) from Media menu.

I am about to test it on ffmpeg | ffplay

1 Like

Thank you both so much, I tried that but I gave up to quickly🙄

Wasn’t Shortwave an option? :stuck_out_tongue:

1 Like

Maybe @epinez but I rather avoid flathub apps for generally use a lot of resources and storage. This is why I made a script with ffmpeg and ffplay which already installed on Librem 5 AFAIK.

1 Like

It occurs to me that all those streaming links will likely include trackers from those websites (as is also the case with apps like Shortwave). Have you considered any solution for preventing tracking? Just curious.

Solutions that come to mind are:

  1. Copy one of the common tracker-blocking scripts from github to the hosts file on the L5.

  2. Always use a VPN that has the option to incorporate such a list into your settings.

  3. Only use the radio links on your home network running the Pi-hole application to block trackers.

  4. Use a browser with javascript- and ad-blocking add-ons, instead of your script or instead of Shortwave-like apps.

  5. Do nothing to prevent tracking. :slight_smile:

I also wonder what info will the .m3u8 link receive from gnu ffmpeg | ffplay in this internetradio.sh script.

It will say in the handshake we are using a Gnu Linux OS?

certainly I do not provide anything of that .

@ASwyD2 I added Kunyo as option O. thanks

Listening Kunyo station:

1 Like

How would that work? :thinking:

Thanks :+1::+1::+1::+1::+1::grinning:

I’m thinking that since the links come from a website, there is the potential to be tracked through the site. :man_shrugging:

I notice that copying one of @Tonyp’s streaming links to a browser’s url bar invokes a download dialog to open an .m3u8 in one’s default player application, so I’m not sure.

In Pi-hole on my network I can see the connection to, as one example, stream.eleden.com/, but there seems to be no data tracker to block, fortunately.

1 Like

Testing some of my saved stations in Shortwave, mostly European music stations, I see connections being made to them in Pi-hole, but again, no apparent trackers. :+1:
(At least, not visible to the user.)

Nothing unusual, every DNS request goes through the Pi-hole in standard configuration :slight_smile:

But tracking is not really a thing here. Just look up the contents of the M3U file in a text editor. It does not work the same as in a browser; an audio player can only play/stream the audio. It does not make any other connections as in the usual tracking game. You would have to route your traffic through a VPN or Tor to hide your IP. User-agent is another thing.

1 Like

Challenge accepted says Surveillance Capitalism?

I’m not at all familiar with the protocol(s) here but the key question would seem to be: what information, if any, goes back in the other direction?

@amarok what can a tracker do when you play with
mpv stream-url
?

About the only thing I know for analytics is that the radio station typically tracks the amount of users connected, sometimes their geolocation (country), along with total concurrent bandwidth used amongst all of them, but that is the extent of it as far as I am aware.

I would rephrase that question as: “Are there any third-party trackers like Facebook, Google, TikTok, or Doubleclick embedded on the websites where those streams originate from?”

It’s not the idea of the first-party activity tracking by a website (or source) that I chose to visit that would concern me.

Admittedly I was just posing the question because I don’t know what goes on behind the scenes when you call up a stream over the internet. :wink: