#!/usr/bin/perl $user = "SaGEDeVille"; $scriptpath = "/wordpress/audioscrobbler/"; $imagefolder = "IMAGES"; $xmlfolder = "XML"; # Open the file for writing. $data_file = 'albums.xml'; open DATAOUT, ">$data_file" or die "can't open $data_file $!"; # Open the file for reading. # let's get a new weeklyalbumchart.xml $url = "http://ws.audioscrobbler.com/1.0/user/$user/toptracks.xml"; $data_file = 'toptracks.xml'; $wgetcmd = "wget \"$url\" -O\"$data_file\" -t3"; unlink($data_file); $result = system("$wgetcmd"); $url = "http://ws.audioscrobbler.com/1.0/user/$user/topartists.xml"; $data_file = 'topartists.xml'; $wgetcmd = "wget \"$url\" -O\"$data_file\" -t3"; unlink($data_file); $result = system("$wgetcmd"); $url = "http://ws.audioscrobbler.com/1.0/user/$user/weeklyalbumchart.xml"; $data_file = 'weeklyalbumchart.xml'; $wgetcmd = "wget \"$url\" -O\"$data_file\" -t3"; unlink($data_file); $result = system("$wgetcmd"); open DATA, "$data_file" or die "can't open $data_file $!"; @lines=; foreach $line (@lines) { if ($line =~ m/.*(.*)<.artist>/i) { $artist = $1; } if ($line =~ m/.*(.*)<.name>/i) { $album = $1; } if ($line =~ m/<.album>/i) { $url = "\"http://ws.audioscrobbler.com/1.0/album/$artist/$album/info.xml\""; $newfile = "$xmlfolder/$artist".'-'."$album".".xml"; if (-e $newfile) { print "CACHED: $artist - $album\r\n"; } else { $wgetcmd = "wget $url -O\"$newfile\" -t3"; $result = system("$wgetcmd"); print "DOWNLOADED: $artist - $album\n$result\r\n"; } print DATAOUT " ".$scriptpath."$imagefolder/$artist-$album.jpg\n\n"; $album = ''; $artist = ''; } else { print DATAOUT $line; } } close DATA; @xmlfiles = grep -T, glob "$xmlfolder/*"; foreach $file (@xmlfiles) { open DATA, "$file" or die "error - file removed while updating!"; print "EXAMINING: $file\r\n"; @lines=; $xmlfile = join('', @lines); if ($xmlfile =~ m/.*(.*)<.large>/si) { $newfile = "$imagefolder/".substr($file, 4, length($file)-8).substr($1, length($1)-4); if (-e $newfile) { print "CACHED: $newfile\r\n"; } else { $wgetcmd = "wget $1 -O\"$newfile\" -t3"; $result = system("$wgetcmd"); print "DOWNLOADED: $newfile\n$result\r\n"; } } close DATA; } close DATAOUT;