Script for listening shoutcast radios

Sathariel created the following script for listening any radio stream station, it requires to create the file ~/.radio, there you should save all your radio stream stations in a list with the following syntax:

TITLE | URL

You can edit this script and replace audacious for your favorite audio player, if you use a cli audio player you can remove the nohup command and the last part too (&> /dev/null &)

#!/bin/sh

[[ ! -f ~/.radio ]] && echo "Configuration file not found" &&  exit 1
opts=$(awk -F'|' '
	BEGIN {
		n = 0
		s = "on"
	}
	{
		n += 1
		printf("%s \"%s\" %s ", n, $1, s)
		s = "off"
	}
	' ~/.radio)
[[ -z $opts ]] && echo "Error reading configuration" && exit 1
 stream=$(echo $opts | xargs dialog --output-fd 1 --radiolist "Select a source" 10 50 10)

[[ $? -eq 0 ]] && nohup audacious $(sed -n ${stream}p ~/.radio | cut -d '|' -f 2) &> /dev/null &

Script for updating A records with shoutcast radios

Many stream radio stations changes its IP, that is the reason I created the following script, its not interactive so you should edit it, replace http://yp.shoutcast.com/sbin/tunein-station.m3u?id=1177763 with the station m3u file that you can find in http://directory.shoutcast.com clicking in download and using the right bottom of mouse.

Then replace xxxxxxxxxxxxxxxxxxxxxxxxx with your Cloudflare api key, and admin@example.com with your Cloudflare email.

Replace aaaaaaaaaaaaaaaaaaaaaa with the zone id and bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb with the dns record (subdomain) id.


a=$(curl -s http://yp.shoutcast.com/sbin/tunein-station.m3u?id=1177763 | tail -1 | cut -d "/" -f 3 | sed -e 's/:.*//g')

curl -X PUT "https://api.cloudflare.com/client/v4/zones/aaaaaaaaaaaaaaaaaaaaaa/dns_records/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" \
	 -H "X-Auth-Email: admin@example.com" \
	 -H "X-Auth-Key: xxxxxxxxxxxxxxxxxxxxxxxxx" \
	 -H "Content-Type: application/json" \
	 --data  $( echo  '{"type":"A","name":"example.com","content":"$a","ttl":120,"proxied":false}' | sed -e "s/\$a/$a/g" )

You can run this script as a cronjob daily:

0 0 * * * bash /home/example/script.sh

You can get the zone id running this command:

curl -X GET "https://api.cloudflare.com/client/v4/zones" \
 -H "X-Auth-Email: admin@example.com" \
-H "X-Auth-Key: xxxxxxxxxxxxxxxxxxxxxxxxx" \
 -H "Content-Type: application/json"

And you can get the DNS record id with the following command:

curl -X GET "https://api.cloudflare.com/client/v4/zones/aaaaaaaaaaaaaaaaaaaaaa/dns_records" \
 -H "X-Auth-Email: admin@example.com" \
 -H "X-Auth-Key: xxxxxxxxxxxxxxxxxxxxxxxxx" \
-H "Content-Type: application/json"

Where do I find my Cloudflare API Key?

These bottons respect your privacy