I've been re-encoding MP3s to higher bitrates, and sometimes when I do, iTunes ends up with duplicates: separate entries in the Library that point to the same file on disk. Weird. So, I wrote a little script to find the duplicates.
use Mac::Glue ':all';
my $itunes = new Mac::Glue 'iTunes';
my $library = $itunes->obj(library_playlist => 1);
my $tracks = $itunes->obj(tracks => $library);
my %tracks;
for my $track ( $itunes->get($tracks) ) {
my $path = $itunes->get( $itunes->prop(location => $track) );
print $path, "\n" if $tracks{$path}++;
}
Also, I keep looking for ways to make Mac::Glue syntax a little nicer, and so I also made a change this morning (I need to play with it a lot more before releasing it):
becomes:
and:
becomes:
That is, $tracks and $track both know their "parent" object, so with some AUTOLOAD magic, we can just use the parent's methods on the "child" objects. You can also do obvious things like $track->play instead of $itunes->play($track). w00p!
I just need to think on this more, though; for the prop method, $track becomes the last parameter to the method when $itunes->prop is called. But for $itunes->play, it would be the first parameter. For now, I am just making it so for obj and prop it goes last, else it goes first, but I might also be able to do some trickier things, if necessary, like looking up the class of $track and seeing which paramter of play accepts that class for its value. Must investigate.