Stories
Slash Boxes
Comments
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)

pudge
  (email not shown publicly)
http://pudge.net/
AOL IM: Crimethnk (Add Buddy, Send Message)

I run this joint, see?

Journal of pudge (1)

Monday May 26, 2003
11:21 AM

iTunes Cleaner

[ #12443 ]

iTunes has a tendency to retain entries in the library to nonexistent files. Here is a little script to tell you which entries in your library are orphans (similar to the duplicate script I posted earlier, but a bit simpler, and on one line because that is how I did it). It optionally deletes them.

perl -MMac::Glue -le '$d = 0; $i = new Mac::Glue "iTunes"; for $t ($i->obj(tracks => library_playlist => 1)->get) { if ($t->prop("location")->get eq "msng") { print join " - ", map { $t->prop($_)->get } qw(name artist album); $t->delete if $d }}'

OK, here it is more readable:

use Mac::Glue;
 
$d = 0;
$i = new Mac::Glue "iTunes";
 
for $t ($i->obj(tracks => library_playlist => 1)->get) {
    if ($t->prop("location")->get eq "msng") {  # 'missing value'
        print join " - ", map { $t->prop($_)->get } qw(name artist album);
        $t->delete if $d
    }
}

It found three tracks off Primus' Sailing the Seas of Cheese album were disappeared. The files are not there. I have no idea why.

Now Playing: Tommy The Cat - Primus (Sailing The Seas Of Cheese)

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • this is a huge problem for me, I like to have a really messy mp3 folder and then clean it all up and end up with tons of dead links in iTunes. I try running this on my jaguar machine and I get this: [mogu:~] rex% perl -MMac::Glue -le '$d = 0; $i = new Mac::Glue "iTunes"; for $t ($i->obj(tracks => library_playlist => 1)->get) { if ($t->prop("location")->get eq "msng") { print join " - ", map { $t->prop($_)->get } qw(name artist album); $t->delete if $d }}' No application glue for
    • shit, I guess pre tags don't work.

      [mogu:~] rex% perl -MMac::Glue -le '$d = 0; $i = new Mac::Glue "iTunes"; for $t ($i->obj(tracks => library_playlist => 1)->get) { if ($t->prop("location")->get eq "msng") { print join " - ", map { $t->prop($_)->get } qw(name artist album); $t->delete if $d }}'
      No application glue for 'iTunes' found in '/Library/Perl/Mac/Glue/glues' at -e line 1
      [mogu:~] rex%
      • You need to create one (you read the Mac::Glue documentation [cpan.org]*, right? ;-).

        % gluemac /Applications/iTunes.app

        You may need to use sudo, or otherwise run as root, as the glue is by default saved into your perl's sitelib path.

        That will create the necessary glue for whatever app you wish to script with Mac::Glue. Use gluedoc iTunes to read the documentation for that created glue file.

        Also, <ECODE> tags are the way to do code on use.perl.org (and many other Slash sites, like Slashdot).

        * The docs are s