Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

pudge (1)

  (email not shown publicly)
AOL IM: Crimethnk (Add Buddy, Send Message)

I run this joint, see?

Journal of pudge (1)

Sunday May 18, 2003
09:06 AM

iTunes Duplicates, Mac::Glue Syntax

[ #12286 ]

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 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->prop(location => $track)



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.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.