#!/usr/bin/perl
# For adding the date
use Time::Local;
$File = "iTunes Music Library.xml";
$SongNumber = 0;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
open (FILE, "$File");
print "\n";
print "
\n";
print "\n";
print "\n";
print "\n";
print "COMPLETE SONG LIST<\h3>\n";
printf "Compiled %02d-%4d
\n", $mon+1, $year+1900;
print "
\n";
print "\n";
print "SONG: | \n";
print "ARTIST: | \n";
print "ALBUM: | \n";
print "
\n";
while () {
chomp;
#Note that Name, Artist, Albuma nd Genre must be in the exact order as they are in the iTunes XML file
if (/>Name){
$prep = s/\r/\n/g;
$prep = s/\r$//g;
$prep = s/\t//g;
$prep = s/Name<\/key>//;
$prep = s/<\/string>//;
$Name = "$_";
chomp $Name;
}
elsif (/>Artist){
$prep = s/\r/\n/g;
$prep = s/\r$//g;
$prep = s/\t//g;
$prep = s/Artist<\/key>//;
$prep = s/<\/string>//;
$Artist = "$_";
chomp $Artist;
}
elsif (/>Album){
$prep = s/\r/\n/g;
$prep = s/\r$//g;
$prep = s/\t//g;
$prep = s/Album<\/key>//;
$prep = s/<\/string>//;
$Album = "$_";
chomp $Album;
$SongNumber++;
}
elsif (/>Genre){
$prep = s/\r/\n/g;
$prep = s/\r$//g;
$prep = s/\t//g;
$prep = s/Genre<\/key>//;
$prep = s/<\/string>//;
$Genre = "$_";
chomp $Genre;
#Once Genre has been captured, we filter out the audiobooks, podcasts and radio stations
if (($Genre eq 'Audiobook') || ($Genre eq 'Podcast') || ($Genre eq 'Radio')){
$SongNumber--;
}
#Here we print out the song info, as part of the genre loop
else {
print "";
print "$Name";
print " | ";
print "$Artist";
print " | ";
print "$Album";
print " | \n";
}
}
}
print "\n";
print "Total number of songs: $SongNumber <\/b>\n";
print "\n";
print "\n";
close FILE;