Stupid Mac::Glue Tricks: Renaming MP3s

| | Comments (0)
I've done something like this before, but I figured others might find this to be especially useful.

iTunes Music Store has some of the 9/11 Commission stuff available for free. But the artist is "Unknown", the Genre is "Classical", and the album name and track name are both of the form "9-11 Commission Hearings: $foo", where $foo is something like "NYC Panel Three (5/18/04)". Also, it has the spurious "Track 1 of 1" and "Disc 1 of 1". At least the year (2004) was correct.

So I selected all the tracks in iTunes and changed the genre to "Audiobooks" and the artist and album to "9-11 Commission Hearings", and removed the track and disc information.

Then I wanted to remove the "9-11 Commission Hearings: " from the beginning of the track name, but by hand that's a pain, since there's 38 tracks. Perl and Mac::Glue to the rescue. Remember, change the info in iTunes first, or else modify the script to match the proper "album" value, perhaps by "contains" or "begins_with" instead of "equals".

(For bonus points: rewrite the script below to order the tracks by date information. Also, consider making the artist the name of the speaker or panel. Also, consider doing everything I did by hand in iTunes with this script.)

#!/usr/local/bin/perl
use strict;
use warnings;
 
use Mac::Glue ':all';
my $itunes = new Mac::Glue 'iTunes';
my $tracks = $itunes->obj(
    tracks => whose(album => equals => '9-11 Commission Hearings'),
    playlist => 1
);
 
for my $track ($tracks->get) {
    my $name = $track->prop('name');
    my $value = $name->get;
    (my $new = $value) =~ s/^9-11 Commission Hearings: //;
    $name->set(to => $new) unless $new eq $value;
}

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 July 19, 2004 9:56 AM.

Replacing Senators was the previous entry in this site.

Tuesday Thoughts is the next entry in this site.

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