iTunes Duplicates, Mac::Glue Syntax

| | Comments (0)
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.

    #!/usr/bin/perl
    use strict;
    use warnings;
 
    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):

$itunes->get($tracks)

becomes:

$tracks->get

and:

$itunes->prop(location => $track)

becomes:

$track->prop('location')

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. use.perl.org

Leave a comment

<pudge/*> (pronounced "PudgeGlob") is thousands of posts over many years by Pudge.

"It is the common fate of the indolent to see their rights become a prey to the active. The condition upon which God hath given liberty to man is eternal vigilance; which condition if he break, servitude is at once the consequence of his crime and the punishment of his guilt."

About this Entry

This page contains a single entry by pudge published on May 18, 2003 7:06 AM.

Features was the previous entry in this site.

Mac::Glue Syntax Revisited is the next entry in this site.

Find recent content on the main index or look in the archives to find all content.