This is a script to obtain the radio channels of a TVheadend server. Placing the result of script on the volumio player in /data/favourites/ with the filename my-web-radio. Be aware if you already a my-web-radio file saved it first. Merging the an existing my-web-radio file with the output of the script is simple cut/paste the output of the script after the first ‘[’ sign and before the corresponding ‘]’ sign. Insert (paste) after the ‘[’ and place at the of the pasted text a comma. (,) Save the the file.
Before using the script you must at the op the ip-addr of your tvheadend server. First it searches for the tagid of the radio channels and the it performs a curl to get all the channels with the founded tagid. You can also add for example channel numbers (ex. music tv stations).
To see the tagid’s run:
curl -s http://${IP}:${PORT}/playlist/tags
#<—%—>
#!/bin/bash
#
# IP of tvheadend server
#
IP="192.168.178.240"
PORT="9981"
TVH_USER=hts
#
# Use it and modified freely
# Louis Mulder
#
# Example regexp (sed format) for more than one radio tags
#
#TAG_RADIO_STRINGS_REGEXP='\(Radio channels\)\|\(Ziggo\)'
#
TAG_RADIO_STRINGS_REGEXP='\(Radio channels\)'
RANGES='{601..613} 538'
#
#http://192.168.178.240:9981/playlist/tagid/901578936?profile=pass #EXTINF:-1 type="playlist",Radio channels
#
PLAYLIST_TAGS=`curl -s http://${IP}:${PORT}/playlist/tags |sed \
-e '/EXTM3U/d' \
-e 'N;s/\n/ /' \
-e '/'"${TAG_RADIO_STRINGS_REGEXP}"'/!d'\
-e 's/\(^.*tagid\)\([/]\)\(..*\)\(\?.*$\)/\3/'
`
FIRST=0
for tag in ${PLAYLIST_TAGS}
do
curl -s http://${IP}:${PORT}/playlist/tagid/${tag}
for i in ${RANGES}
do
for chno in `eval echo ${i}`
do
OUT="`curl -s http://${IP}:${PORT}/playlist/channelnumber/${chno}`"
case "${OUT}" in
#(
*EXTINF* ) echo "${OUT}"
;;
#(
* ) :
;;
esac
done
done
done |expand|sed -e '/EXTM3U/d' \
-e 'N;s/\n/ /' \
-e 's/,/ tvg-name="/'\
-e 's/ http/" tvg-uri="&/'\
-e 's/ http/http/g'\
-e 's/\#/tvg-dummy="/'\
-e 's/ /"&/' \
-e 's/tvg-/&/g' \
-e 's/$/"/'\
-e 's/tvg-/tvg_/g' | while read line
do
[ "${line}" != '' ] && eval ${line}
if [ "${FIRST}" = "0" ]
then
echo -n '['
FIRST=1
else
echo ','
fi
echo -n '{"service": "webradio","title": "'"${tvg_name}"'","name": "'"${tvg_name}"'","uri": "'"${tvg_uri}"'","icon": "'"${tvg_logo}"'"}'
done
echo ']'
Save the script as get-radiochannels.sh, chmod 755 get-radiochannels.sh and run it as; ./get-radiochannels.sh output will appear on stdout.
Regards Louis