############################################################################### # # itunes_artist_album_listing.pl # # This script will generate a text file showing album names for each artist # in your Library. # # Copyright (C) 2007 Robert Jacobson # written by: Robert Jacobson (http://teridon.googlepages.com/itunesscripts) # Last Updated: 28 Jan 2007 # Version 1.0 # # This script is GPL v2. see http://www.gnu.org/copyleft/gpl.html # ############################################################################### use File::Basename; my $PROGNAME = basename($0); my $VERSION = "1.0"; my $AUTHOR = "Robert Jacobson"; my $HOMEPAGE = "http://teridon.googlepages.com/"; my $YEAR = 2007; my $GNU_URL = "http://www.gnu.org/copyleft/gpl.html"; { print "**************************************************************\n" . "$PROGNAME version $VERSION, Copyright (C) $YEAR $AUTHOR\n" . "Visit $HOMEPAGE for updates\n" . "$PROGNAME comes with ABSOLUTELY NO WARRANTY;\n". "This is free software, and you are welcome\n" . "to redistribute it under certain conditions\n" . "for details see $GNU_URL.\n" . "**************************************************************\n" . "\n" ; } use strict; use Win32::OLE; ## Create the OLE Object my $iTunes = Win32::OLE->new('iTunes.Application') or die Win32::OLE->LastError(); my $playlist = $iTunes->LibraryPlaylist(); my $playlist_name = $playlist->Name(); #print "You selected $playlist_name\n"; my $tracks = $playlist->Tracks; my $num_tracks = $tracks->Count(); #print "\t$num_tracks tracks\n"; $| = 1; print "Running"; my $userprof = $ENV{USERPROFILE}; open (OUT, ">$userprof\\Desktop\\albumlisting.txt") or die "could not open output file on Desktop: $!"; my %seen; # Get all the tracks in the playlist for (my $k = 1 ; $k <= $tracks->Count ; $k++ ) { #print "num: " , $num_tracks , " Count: ", $tracks->Count , " k: ", $k , "\n"; my $track = $tracks->Item($k); my $track_kind = $track->Kind(); if ($track_kind == 1) { # File #my $songname = $track->Name(); my $artist = $track->Artist(); my $album = $track->Album(); $seen{$artist}{$album}++; print "."; } } for my $artist (sort keys %seen) { print OUT "$artist\n---------------\n"; for my $album ( sort keys %{ $seen{$artist} } ) { next if ($album eq ""); print OUT "\t$album\n"; } } print "\nDone\n"; # Destroy the object. Otherwise zombie object will come back # to haunt you quit(); sub quit { # This destroys the object undef $iTunes; }