Skip to content

Instantly share code, notes, and snippets.

@lwalen
Created April 7, 2014 01:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lwalen/10013433 to your computer and use it in GitHub Desktop.
Save lwalen/10013433 to your computer and use it in GitHub Desktop.
Returns a list of artists with only one song from a given iTunes library or playlist file
#!/usr/bin/env perl
use v5.10;
use Mac::iTunes::Library;
use Mac::iTunes::Library::XML;
use Mac::iTunes::Library::Playlist;
my $library = Mac::iTunes::Library::XML->parse(@ARGV[0]);
my %results;
my %items = $library->items();
while (($artist, $artistSongs) = each %items) {
if ((keys %$artistSongs) == 1) {
while (($songName, $artistSongItems) = each %{$artistSongs}) {
foreach my $item (@$artistSongItems) {
$results{$artist} = $item->name();
}
}
}
}
foreach my $key (sort { lc($a) cmp lc($b) } keys %results) {
say "$key\t$results{$key}";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment