Skip to content

Instantly share code, notes, and snippets.

@frafra
Created July 10, 2013 14:05
Show Gist options
  • Save frafra/5966556 to your computer and use it in GitHub Desktop.
Save frafra/5966556 to your computer and use it in GitHub Desktop.
Little project for generating United Music web radios XSPF playlist
#!/bin/bash
#
# Copyright (C) 2013 Francesco Frassinelli (FraFra - http://frafra.eu)
# License: GPLv3
#
# Special thanks to: http://blog.redaelli.eu/2010/03/lista-di-radio-su-unitedradioit.html
filename="unitedradio-it.xspf"
server="http://shoutcast.unitedradio.it"
array=()
for port in $(seq 1100 1600); do
name=$(curl -s $server:$port | grep -am 1 icy-name: | tr -d "\r" | cut -f 2 -d :)
if [ -n "$name" ]; then
array+=("$name;$server:$port")
fi
done
cat > $filename << EOL
<?xml version="1.0" encoding="UTF-8"?>
<playlist version="1" xmlns="http://xspf.org/ns/0/">
<trackList>
EOL
readarray -t sorted < <(for line in "${array[@]}"; do echo "$line"; done | sort)
for line in "${sorted[@]}"; do
IFS=';' station=($line)
cat >> $filename << EOL
<track>
<title>${station[0]}</title>
<location>${station[1]}</location>
<album>United Music</album>
</track>
EOL
done
cat >> $filename << EOL
</trackList>
</playlist>
EOL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment