Set tags on current title in iTunes based on top3 from last.fm

I kinda lacked a function that would automaticly set tags on my tracks according to e.g. last.fm

I therefore wrote a bashscript that leeches the three most popular tags for a given bandname and applied them to the track.
I can then just use iTunes to use these tags for the entire album.

It is not perfect but it is a start for making tagging easier, for me atleast.
I hope some of you will find it useful or inspiring.

#!/bin/bash
TAGS="extract.txt"


TITLE=`exec osascript <<\EOF 
tell application "iTunes"
	get artist of current track
		--set genre of current track to "HORSE POP"
 end tell`

echo "Fetching tags for: "  $TITLE

TITLE=`echo $TITLE|sed 's/\ /+/g'`
wget -q  http://last.fm/music/$TITLE/+tags  
sed -n  's/rel="tag"//p' +tags >> $TAGS
TAGLIST=`awk '{print $4,$6,$7,$8,$9,$10}' $TAGS |sort -r|head -3|sed 's/.*\" >//g'|sed 's/<\/a>//g'`
TAGLIST=$( echo "${TAGLIST}" | awk '{for(i=1;i<=NF;i++)sub(/./,toupper(substr($i,1,1)),$i)}1' )
echo $TAGLIST > $TAGS


echo "Setting tags to :" $TAGLIST
NEWTAGS=`exec osascript <