More iTunes pain

brian_d_foy on 2004-08-27T05:02:22

A while ago I had to clean up some MP3 info for a Teaching Company course. Now I have to do it again.

I have Timothy Taylor's "Economics" lecture series, and I want to listen to them sequentially. My iPod seems to have trouble with that because the tracks have duplicated names, inconsistent names, and so on. I want them to comprise the disk and track number so they line up correctly.

I could have done this with Applescript, but just starting up Script Editor seemed too painful.

#!/usr/local/bin/perl
use warnings;
use strict;
 
use Mac::Glue ':all';
 
my $itunes = Mac::Glue->new( 'iTunes' );
 
$itunes->activate;
  
my $playlist  = $itunes->prop(view => window => 1);
my @tracks = $playlist->obj('file_tracks')->get;
  
foreach my $item ( @tracks ) 
	{
	my $disk  = $item->prop( 'disc_number' )->get;
	my $track = $item->prop( 'track_number' )->get;
	
	$item->prop( 'name' )->set( to => 
		sprintf "Lesson %02d-%02d", $disk, $track );
	}