Forum › Forums › General › Tips and Tricks › Tunein Radio – how to make a terminal radio player
- This topic has 29 replies, 8 voices, and was last updated May 11-5:08 pm by wildstar84.
-
AuthorPosts
-
May 4, 2023 at 1:37 pm #105961Member
Lead Farmer
Although I think PMRP is ok, is lacking local stations and lack of stations in general, so I decided make an alternative to PMRP with Tunein. stations.
This guide is a little complex and will take about 10 min to build your own radio player
Step 0
Make folder in your PC and name it “tunein_redio” for this example, make sure you save all the files in this folder, the change the path in the scripts.
Step 1
In the link I post above you will see categories for this example I will show how to add rock stations.
In the web page scroll down until you see “See More” to load more stations, you can load as match as you like.
save the web page with ctrl+s and save it in the folder as rock.htmlStep 2
Now we need to extract the URLs of the station to text file by using this command, change the path of the folder.
grep -Po "(?<=href=\")https:\/\/tunein.com\/radio\/[\w-]+s\d+" path/tunein_redio/rock.html | sort -u >> path/tunein_redio/rock.txtOptional: At this point you can edit text file by removing or adding stations or changing the order if you like.
Step 3
In this step we will make a new text file consist of 3 columns numbers, station name and url from the file rock.txt.
The new file will be name 3.txt because it is the third entry in my radio player see image.#!/bin/bash # # Tunein radio player 1.0 # make a 3 column txt file number/satation name/url folder="/path/tunein_redio" number_stations=$(cat $folder/rock.txt | wc -l) for ((i = 1 ; i <= $number_stations ; i++)); do station_url=$(cat $folder/rock.txt | head -$i | tail +$i) sname=$(echo "$station_url" | grep -Po '[\w-]+(?=-s\d+)') echo "$i $sname $station_url" >> $folder/3.txt done exit 0You can save this script, and change the values for each category.
Step 4
This is the script of the radio player save and run it from the terminal or make a menu entry.
#!/bin/bash # # Tunein radio player 1.0 # folder="path/tunein_redio" while true; do clear echo -e "Tunein Radio\n\n1 Local\n2 Top 40 & Pop\n3 Rock\n4 Indie\n5 Dance Electronic\n6 Classical\n7 Jezz" echo -e "\nSelect category number, Enter to exit" read category [[ $category -eq 0 ]] && exit 0 while true; do clear cat $folder/$category.txt | awk '{print $1" "$2}' echo -e "\nSelect station number, 0 random station, b back" read station [[ "$station" == "b" ]] && break if [[ "$station" == "0" ]]; then number_stations=$(cat $folder/$category.txt | wc -l) station=$(echo $((1 + $RANDOM % $number_stations))) fi station_url=$(cat $folder/$category.txt | head -$station | tail +$station | awk '{print $3}') station_name=$(cat $folder/$category.txt | head -$station | tail +$station | awk '{print $2}' |tr '-' ' ') clear echo -e "Playing $station_name station, q to stop\n\n" mpv $station_url done done exit 0In the 8 line you can see 3 rock corresponding to 3.txt, make sure to change the name of the files for each category.
Step 5
Repeat 1-4 step for other categories.
Edit: I post version 2.0 below.
- This topic was modified 1 week ago by Lead Farmer.
- This topic was modified 1 week ago by Lead Farmer.
- This topic was modified 6 days, 8 hours ago by Lead Farmer.
May 4, 2023 at 4:13 pm #105978Member
marcelocripe
May 4, 2023 at 5:33 pm #105989MemberLead Farmer
May 4, 2023 at 9:27 pm #105996Moderator
christophe
::This looks great. I love seeing this type of thing in tips & tricks. I’ll dig into this soon, when I get time…
Thanks.confirmed antiX frugaler, since 2019
May 5, 2023 at 12:28 pm #106027MemberLead Farmer
::Version 2.0
-
New Features:
Save previous station in favorites, after you finished listing to a station you can save it favorites, it’s good if you have a lot a stations.
-
Changes
1) Bug fixing.
2) I changed so back or exit is the q key
3) I changed the code so it be easier to change the categoriesfavorite_entry=8 category_entries() { # You can change this section! # Make sure the text files corresponding to the category # 3 rock = 3.txt echo -e "Tunein Radio\n 1 Local 2 Top 40 & Pop 3 Rock 4 Indiet 5 Dance Electronic 6 Classical 7 Jezz $favorite_entry Favorites" #Favorites must be the last one! # set favorite_entry abouve to the right value that fit the order }-
Instructions
1) extract the files to your tunein folder
2) the empty file 8.txt is the favorites rename as your last category, for example you have 12 categories rename the file 12.txt, also you need to set favorite_entry=12.This is only the player (step 4) and it will work with text files 1.txt, 2.txt… to show and play the stations.
- This reply was modified 6 days, 8 hours ago by Lead Farmer.
- This reply was modified 6 days, 7 hours ago by Lead Farmer.
May 5, 2023 at 3:07 pm #106040MemberTrashthrasher
::Cool, I’ll check this out tonight!!!
Animal lover
Savior of abandoned electronics
Linux Enthusiast
Check out my Punk/Metal band Taco TuesdayMay 9, 2023 at 4:05 pm #106324MemberLead Farmer
::Version
3.23.3New Features:
1) Recorded stream: add r to record a station like -> r10 to record the 10 stations, recordings saved in the recording folder in the tunein_redio folder.
Recording is an experimental feature, and might not work or change the audio quality2) Save station in Favorites:
– Add s in the beginning of the number station to save it in favorites like s10
– s alone will save the previous listened station.3) Delete station:
– Add d in the beginning of the number station -> d10
– d alone will delete the previous listened station
– I recommend to backup you stations files 1.txt, 2.txt… just in case before using this feature4) Add help
Instructions
1) extract the files to your tunein folder
2) the empty file 8.txt is the favorites rename as your last category, for example you have 12 categories rename the file 12.txt, also you need to set favorite_entry=12.
This is only the player (step 4) and it will work with text files 1.txt, 2.txt… to show and play the stations.
Helped needed
I noticed that about 10% of the stations are not playing and there is an error with mpv player,
I think it’s IP blocked
mpv https://tunein.com/radio/1003-RB-and-Hip-Hop-s59419 [ffmpeg] https: HTTP error 403 Forbidden Failed to open https://playerservices.streamtheworld.com/api/livestream-redirect/WRNBFM.mp3?DIST=TuneIn&TGT=TuneIn&maxServers=2&partnertok=eyJhbGciOiJIUzI1NiIsImtpZCI6InR1bmVpbiIsInR5cCI6IkpXVCJ9.eyJ0cnVzdGVkX3BhcnRuZXIiOnRydWUsImlhdCI6MTY4MzY0NjMxNCwiaXNzIjoidGlzcnYifQ.3SAtAOkh67m7OwjK-Ajaz57NBzOPHR-JIVTCca8sJYw.And this one.
mpv https://tunein.com/radio/100hitz---90s-Alternative-s111386 [ffmpeg] http: HTTP error 404 Not Found .ailed to open http://pureplay.cdnstream1.com/6040_128.mp3If you know how to get around the second error please tell.
Edit: version 3.3 is because I forgot to add the word “delete” in the script.
Mods: Please remove the third pic
- This reply was modified 1 day, 19 hours ago by Lead Farmer.
- This reply was modified 1 day, 19 hours ago by Lead Farmer.
- This reply was modified 1 day, 19 hours ago by Lead Farmer.
May 9, 2023 at 5:16 pm #106338MemberRJP
::streamtheworld.com > Access to resource is forbidden.
http://pureplay.cdnstream1.com/6040_128.mp3 > works ok
May 9, 2023 at 8:43 pm #106346MemberRobin
::I noticed the about 10% of the stations are not playing and there is an error with mpv player,
This is due to silly geoblocking, and you can’t make it work for all people the same in your script: In some places some 10% or 30% fail, in other countries different 10% or 30% fail, and so on. Everybody will have to check the addresses provided on his own. We do live in a globalised world, but there are new virtual concrete walls for internet citizens, just like the Berlin Wall, only erected to protect some outdated business models.
Windows is like a submarine. Open a window and serious problems will start.
May 10, 2023 at 1:02 am #106362MemberLead Farmer
::streamtheworld.com > Access to resource is forbidden.
http://pureplay.cdnstream1.com/6040_128.mp3 > works ok
This script is build around Tunein radio stations, so making it to work with other streams is not passable.
I noticed the about 10% of the stations are not playing and there is an error with mpv player,
This is due to silly geoblocking, and you can’t make it work for all people the same in your script: In some places some 10% or 30% fail, in other countries different 10% or 30% fail, and so on. Everybody will have to check the addresses provided on his own. We do live in a globalised world, but there are new virtual concrete walls for internet citizens, just like the Berlin Wall, only erected to protect some outdated business models.
That a shame that there is such restrictions.
The user will have to manage their stations, either ignore or delete the the non playing stations.
I have +5k stations so it will take me some time to remove them all, but I think I will do it only when I encounter a non playing station.- This reply was modified 1 day, 19 hours ago by Lead Farmer.
- This reply was modified 1 day, 19 hours ago by Lead Farmer.
May 10, 2023 at 2:50 am #106370MemberLead Farmer
::Version 3.4
-Bug fixing.
- This reply was modified 1 day, 17 hours ago by Lead Farmer.
Attachments:
May 10, 2023 at 3:57 am #106373MemberRJP
::I cannot get Step 2 working, so could you provide ready file for Step 2?
Step 2
Now we need to extract the URLs of the station to text file by using this command, change the path of the folder
- This reply was modified 1 day, 16 hours ago by RJP.
May 10, 2023 at 4:31 am #106378MemberLead Farmer
::I cannot get Step 2 working, so could you provide ready file for Step 2?
You need to change the path of the folder in the script “path/tunein_redio/rock.html” and “path/tunein_redio/rock.txt”, do it in the other scripts too.
Edit: In step 3 you need to change also the file names
Here is an example of step 1-3
- This reply was modified 1 day, 16 hours ago by Lead Farmer.
- This reply was modified 1 day, 16 hours ago by Lead Farmer.
Attachments:
May 10, 2023 at 4:56 am #106382MemberRJP
::It works. 🙂 The biggest problem with Tunein Radio is getting Step 2 file, so you could incude the files inside Tunein Radio folder and/or make a full deb-package so then paths would be ready out of box. Anyway very good cli-application. 🙂
- This reply was modified 1 day, 15 hours ago by RJP.
May 10, 2023 at 5:31 am #106384MemberLead Farmer
::It works.The biggest problem with Tunein Radio is getting Step 2 file
The process might be hard to understated but it’s easy when you know what to do.
I recommend downloading all html files of the categories you want, then run step 2 from the terminal, and them run step 3 from a script.so you could incude the files inside Tunein Radio folder
I don’t what to give prepacked stations, my music taste may different then yours, also I like to listing to my local station but they different language then yours.
So I prefer people to personalized their player, but also as @Robin said some stations that work for me might for you.make a full deb-package so then paths would be ready out of box. Anyway very good cli-application
I’m just novice, I don’t know how to that.
- This reply was modified 1 day, 15 hours ago by Lead Farmer.
- This reply was modified 1 day, 14 hours ago by Lead Farmer.
-
AuthorPosts
- You must be logged in to reply to this topic.








