feat(init): Initial config

main
ydreniv 2023-01-25 10:14:10 +00:00
parent 4b3280dc42
commit caca9fea92
2 changed files with 29 additions and 1 deletions

View File

@ -1,3 +1,6 @@
# somafm-scripts
A collection of scripts about SomaFM
* `random-somafm.sh` : Picks up a random SomaFM station
Unfortunately, it requires xmllint, which is not installed on Tilde Town.

25
random-somafm.sh 100755
View File

@ -0,0 +1,25 @@
# This script aims at getting a random SomaFM channel
# I may make it a "SOMAFM channel library" if I feel like it.
#
# 2023 - ydreniv
XML_URL="https://somafm.com/channels.xml"
XML_DOC="/tmp/somafm_channels.xml"
curl "$XML_URL" -o $XML_DOC -s
# get the number of channels
channel_count=$(xmllint --xpath 'count(/channels/channel)' "$XML_DOC")
echo "There are $channel_count channels."
# print all channels ID
# xmllint --xpath '/channels/channel/@id' "$XML_DOC"
# get random channel
rdnum=$(( ( RANDOM % $channel_count ) + 1 ))
chan_name=$(xmllint --xpath "/channels/channel[$rdnum]/title/text()" "$XML_DOC" --nocdata)
chan_pls=$(xmllint --xpath "/channels/channel[$rdnum]/highestpls/text()" "$XML_DOC")
chan_id=$(xmllint --xpath "string(/channels/channel[$rdnum]/@id)" "$XML_DOC")
chan_url="https://somafm.com/$chan_id"
echo "$chan_name - $chan_url : $chan_pls"