if [ ! -d $1 ]
then
  echo "Anna alihakemiston nimi!"
  exit
fi

mkdir artistpages.$1
cd artistpages.$1
wget `awk 'BEGIN{FS="\""}/tag=listing_song_artist/{gsub("?tag=listing_song_artist","")
      print "http://music.download.com"$2}' \
      ../mainpages.$1/*  | uniq`

cd ..
awk '/http:\/\/dw.com.com\/redir\?\&destUrl/ {print}' \
artistpages.$1/* | \
awk 'BEGIN{FS="&"}
     {gsub("http...dw.com.com.redir..destUrl.","")
      gsub("%3A",":")
      gsub("%2F","/")
      gsub("<a href=\"","")
      gsub(" ","")
      print $1}' - \
| sort | uniq > dllist.$1

cd $1
for i in `cat ../dllist.$1`  ; do wget -nc $i ; done
cd ..

rm -rf artistpages.$1
rm -rf mainpages.$1
