Topic: internoderadio.sh - Maintains Internode unmetered radio list
Hi all,
Here's a script I developed to keep the Internode unmetered content updated in My Streams on my chumby, and includes all unmetered content (not just the shorter list in the Internode radio audio source).
This script should keep your custom streams across refreshes and only update the internode unmetered streams (either way it makes a backup anyway). Custom entries will appear at the top of the new list, with the internode items following.
Anyway I hope someone finds this useful and if not be gentle as this script is not much more than a series of ugly grep and sed hacks! wink
Enjoy!
Clippy
PS: If you used servalan's listing from here ( http://forum.chumby.com/viewtopic.php?id=3222 ) you will need to delete those entries manually (sorry!) as she linked to the source stream whereas I have linked to the playlist which contains a link to the source stream
#!/bin/sh
# setup
ignored_streams="(low)"
high_priority_streams="SomaFM|SkyFM|DI:|Afterhours|80s|ABC Classic|Jazz|Lounge|Cody|ETN|Swiss"
low_priority_streams="ChroniX"
target_file=/psp/url_streams
src_url=http://media.on.net/radio.php?mode=playlist
tmp_prefix=/tmp/InterNodeFreeRadio.$$
# housekeeping
touch $target_file
#head $target_file
# backup to be sure
echo Backing up $target_file to $target_file.backup ...
cp -f $target_file $target_file.backup
# download source url
echo
echo Downloading Internode unmetered content listing...
echo
wget --output-document=$tmp_prefix.pls $src_url
# horribleness to parse out the stream names and locations
echo Parsing Internode unmetered content listing...
egrep "^File|^Title" $tmp_prefix.pls | sed "N;s/\n/ /" | sed 's/^File/<stream id="/g;s/=http/" mimetype="audio\/mpeg" url="http/g;s/Title[0-9]*=/name="Node: /g;s/ name="/" name="/g;s/$/" \/>/g' | egrep -i -v "$ignored_streams" | sed 's/Digitally Imported/DI/g;s/Sky.FM -/SkyFM:/g;s/ (High)//g;s/&/and/g' | sed "s/'//g" > $tmp_prefix.incoming.tmp
#head $tmp_prefix.incoming.tmp
echo `grep -i url= $tmp_prefix.incoming.tmp | wc -l | sed 's/\/.*$//g'` unmetered streams found.
# more horribleness to parse out free streams from the existing list
echo Parsing existing my My Streams content...
sed 's/></>\n</g' $target_file | grep -i "url=" | grep -i -v "http://[^.]*.internode.on.net" | uniq > $tmp_prefix.current.tmp
#head $tmp_prefix.current.tmp
echo `grep -i url= $tmp_prefix.current.tmp | wc -l | sed 's/\/.*$//g'` personal streams found.
cat $tmp_prefix.current.tmp
# join 'em up
# echo
echo Updating My Streams content...
echo "<streams>" > $tmp_prefix.outgoing.tmp
cat $tmp_prefix.current.tmp >> $tmp_prefix.outgoing.tmp
cat $tmp_prefix.incoming.tmp | egrep -i "${high_priority_streams}" | egrep -iv "${low_priority_streams}" >> $tmp_prefix.outgoing.tmp
cat $tmp_prefix.incoming.tmp | egrep -iv "${high_priority_streams}" | egrep -iv "${low_priority_streams}" >> $tmp_prefix.outgoing.tmp
cat $tmp_prefix.incoming.tmp | egrep -iv "${high_priority_streams}" | egrep -i "${low_priority_streams}" >> $tmp_prefix.outgoing.tmp
echo "</streams>" >> $tmp_prefix.outgoing.tmp
# finished product
cat $tmp_prefix.outgoing.tmp > $target_file
# done
echo `grep -i url= $target_file | wc -l | sed 's/\/.*$//g'` streams now in My Streams list.
echo
sync
grep -i "stream id" ${target_file} | sed 's/^.* name="//g;s/".*$//g'
echo
# clean up
rm -f $tmp_prefix*