Jump to content


Photo

Bash script for creating bouquet list from webradio api

webradio api bouquet

  • Please log in to reply
2 replies to this topic

#1 eura

  • Senior Member
  • 83 posts

+5
Neutral

Posted 21 August 2022 - 14:59

Just made a quick bash script for creating bouquet files asking http://de1.api.radio...o/#List_of_tags api:s base on music style since I like to use the bouquet than I don’t need to have the Tv on for changing channels. Enjoy

As I say it was quick made so it can be improved! But working.

#!/bin/bash
dest=/tmp
read -p 'Enter music style : ' tag
wget -O $dest/radio_search.tmp http://de1.api.radio-browser.info/json/tags/$tag
cat $dest/radio_search.tmp| sed 's/","/\n/g'| sed 's/stationcount"://'| sed 's/},{"name":"/\t/'
read -p 'Choose one of the above choices : ' tag
wget -O $dest/radio_search.tmp http://de1.api.radio-browser.info/json/stations/bytag/$tag
cat -n $dest/radio_search.tmp | sed 's/","/\n/g'| grep "url\""|sed 's/url\"\:\"//g'>$dest/radio_url.tmp
cat -n $dest/radio_search.tmp | sed 's/","/\n/g'| grep "name\""|sed 's/name\"\:\"//g'>$dest/radio_name.tmp
cat -n $dest/radio_search.tmp | sed 's/","/\n/g'| grep "language\""|sed 's/language\"\:\"//g'>$dest/radio_language.tmp
cat -n $dest/radio_search.tmp | sed 's/","/\n/g'| grep "bitrate\""|sed 's/bitrate\"\:\"//g'|sed 's/,"hls*.*//'|sed 's/"//'>$dest/radio_bitrate.tmp
sed -i 's/:/%3a/g' $dest/radio_url.tmp
sed -i 's/^/#SERVICE 4097:0:2:0:100D:0:0:0:0:0:/' $dest/radio_url.tmp
sed -i 's|$|:|' $dest/radio_url.tmp
# Add #DESCRIPTIO lang and bitrate to name file
sed -i 's/^/#DESCRIPTION /' $dest/radio_name.tmp 
paste -d ":" $dest/radio_name.tmp $dest/radio_language.tmp>$dest/radio_name.tmp1
paste -d ":" $dest/radio_name.tmp1 $dest/radio_bitrate.tmp>$dest/radio_name.tmp2
read -p 'Enter name for the new bouquet file. userbouquet.???????.radio: ' name
# Merge Url and name to one file
echo "#NAME $name">$dest/userbouquet.$name.radio
paste -d \\n $dest/radio_url.tmp $dest/radio_name.tmp2>>$dest/userbouquet.$name.radio
# Delete low bitrate 32,48,56,64,96 and the line above
sed -i 's/bitrate:32$/remove/' $dest/userbouquet.$name.radio
sed -i 's/bitrate:48$/remove/' $dest/userbouquet.$name.radio
sed -i 's/bitrate:56$/remove/' $dest/userbouquet.$name.radio
sed -i 's/bitrate:64$/remove/' $dest/userbouquet.$name.radio
sed -i 's/bitrate:96$/remove/' $dest/userbouquet.$name.radio
sed -i 'N;/remove/!P;D' $dest/userbouquet.$name.radio
no=$(cat $dest/userbouquet.$name.radio| wc -l)
let "no=($no-1)/2"; echo Adding $no stations to /etc/enigma2/userbouquet.$name.radio
read -p 'yes/no ? : ' i
if [[ "$i" == "yes" ]]; then
    mv $dest/userbouquet.$name.radio /etc/enigma2/userbouquet.$name.radio
    echo "Reload userbouquet "
    wget -qO - "http://127.0.0.1/web/servicelistreload?mode=0"
fi
rm -rf $dest/radio_*.tmp* 
rm -rf $dest/userbouquet.$name.radio 
exit

 

 



Re: Bash script for creating bouquet list from webradio api #2 demosat1

  • Senior Member
  • 367 posts

+6
Neutral

Posted 22 August 2022 - 12:02

Thank you for this sharing. :)



Re: Bash script for creating bouquet list from webradio api #3 eura

  • Senior Member
  • 83 posts

+5
Neutral

Posted 23 August 2022 - 19:19

I made a few changes cleaning of forbidden characters in tags for auto naming of the bouquet file that works in most of the cases. Notes that if you search e.g only rock it take some time

for creating the bouquet file on my Ultimo4K when adding 2210 stations.
real    5m40.996s
user    5m13.491s
sys    0m0.604s
 

Added some progress information.

 

#!/bin/bash
dest=/tmp
read -p 'Enter music style : ' tag
wget -O $dest/radio_search.tmp http://de1.api.radio-browser.info/json/tags/$tag
cat $dest/radio_search.tmp| sed 's/","/\n/g'| sed 's/stationcount"://'| sed 's/},{"name":"/\t/'
read -p 'Choose one of the above choices : ' tag
wget -O $dest/radio_search.tmp http://de1.api.radio-browser.info/json/stations/bytag/$tag
echo "1 of 4 files will be created"
cat -n $dest/radio_search.tmp | sed 's/","/\n/g'| grep "url\""|sed 's/url\"\:\"//g'>$dest/radio_url.tmp
echo "File one is ready" 
cat -n $dest/radio_search.tmp | sed 's/","/\n/g'| grep "name\""|sed 's/name\"\:\"//g'>$dest/radio_name.tmp
echo "File two is ready"
cat -n $dest/radio_search.tmp | sed 's/","/\n/g'| grep "language\""|sed 's/language\"\:\"//g'>$dest/radio_language.tmp
echo "File tree is ready"
cat -n $dest/radio_search.tmp | sed 's/","/\n/g'| grep "bitrate\""|sed 's/bitrate\"\:\"//g'|sed 's/,"hls*.*//'|sed 's/"//'>$dest/radio_bitrate.tmp
echo "File four is ready :-)"
sed -i 's/:/%3a/g' $dest/radio_url.tmp
sed -i 's/^/#SERVICE 4097:0:2:0:100D:0:0:0:0:0:/' $dest/radio_url.tmp
sed -i 's|$|:|' $dest/radio_url.tmp
# radio_url.tmp finish
# Cleaning the tag of forbidden characters
echo $tag|
sed 's/!/_/g'|
sed 's/"/_/g'|
sed 's/#/_/g'|
sed 's/$/_/g'|
sed 's/&/_/g'|
sed "s/'/_/g"|
sed 's/(/_/g'|
sed 's/)/_/g'|
sed 's/*/_/g'|
sed 's/;/_/g'|
sed 's/</_/g'|
sed 's/=/_/g'|
sed 's/>/_/g'|
sed 's/?/_/g'|
sed 's/\[/_/g'|
sed 's/\//_/g'|
sed 's/\]/_/g'|
sed 's/\^/_/g'|
sed 's/`/_/g'|
sed 's/{/_/g'|
sed 's/|/_/g'|
sed 's/}/_/g'|
sed 's/~/_/g'|
sed 's/@/_/g'|
sed 's/\//_/g'|
sed 's/~/_/g'|
sed 's/:/_/g'|
sed 's/,/_/g'|
sed 's/ /_/g'|
sed 's/_$//g'|
sed 's/„/_/g'|
sed 's/\"/_/g'|
sed 's/“/_/g'|
# Replays to only one _ in the filename
sed -r 's|_+|_|g'>$dest/radio_new_tag.tmp
name=$(cat $dest/radio_new_tag.tmp)
# Add #DESCRIPTIO lang and bitrate to name file
sed -i 's/^/#DESCRIPTION /' $dest/radio_name.tmp 
paste -d ":" $dest/radio_name.tmp $dest/radio_language.tmp>$dest/radio_name.tmp1
paste -d ":" $dest/radio_name.tmp1 $dest/radio_bitrate.tmp>$dest/radio_name.tmp2
echo
echo "Is this a correct file name and description of the new userbouquet file?"
echo
echo "userbouquet.$name.radio"
read -p 'y/n ? : ' i
echo
	if [[ "$i" == "n" ]]; then
    read -p 'Enter the new filename. userbouquet.??????.radio: ' name
	fi
# Merge Url and name to one file
name_upper="${name^}"
echo "#NAME $name_upper">$dest/userbouquet.$name.radio
paste -d \\n $dest/radio_url.tmp $dest/radio_name.tmp2>>$dest/userbouquet.$name.radio
# Delete low bitrate 32,48,56,64,96 and the line above
sed -i 's/bitrate:32$/remove/' $dest/userbouquet.$name.radio
sed -i 's/bitrate:48$/remove/' $dest/userbouquet.$name.radio
sed -i 's/bitrate:56$/remove/' $dest/userbouquet.$name.radio
sed -i 's/bitrate:64$/remove/' $dest/userbouquet.$name.radio
sed -i 's/bitrate:80$/remove/' $dest/userbouquet.$name.radio
sed -i 's/bitrate:96$/remove/' $dest/userbouquet.$name.radio
sed -i 'N;/remove/!P;D' $dest/userbouquet.$name.radio
no=$(cat $dest/userbouquet.$name.radio| wc -l)
let "no=($no-1)/2"; echo Adding $no stations to /etc/enigma2/userbouquet.$name.radio
read -p 'yes/no ? : ' i
	if [[ "$i" == "yes" ]]; then
    	mv $dest/userbouquet.$name.radio /etc/enigma2/userbouquet.$name.radio
    	echo "Reload userbouquet "
    	wget -qO - "http://127.0.0.1/web/servicelistreload?mode=0"
	fi
rm -rf $dest/radio_*.tmp* 
rm -rf $dest/userbouquet.$name.radio 
exit

 





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users