Batch edit ID3 music tags using custom algorithm

applescriptautomationid3-tagitunesmusic

I like to keep my iTunes library organised and all files well-tagged, so I often spend enjoyable yet unreasonably long amounts of time editing all the ID3 tags manually. Call it OCD or perfectionism, that's how I roll. Thankfully, iTunes is rather convenient for basic operations like batch-changing tags or artworks, but it only goes so far. The problem is that for much music I get, the tags have to be edited for each track individually, taking into account details like numbers and such. Here's an example of what I mean:

Track names and numbers need individual formatting

Notice that files have no embedded track numbers, and are numbered within the track name instead. This picture is more to my liking:

Manually renamed and retagged tracks

To achieve this within bare iTunes, one would have to input track numbers by hand and then remove the ХХ - from each name. Now, I can of course do this by repeatedly mashing the favoured combo (holding : Left Mouse Button), but when I need it for 300 tracks across numerous albums, this turns into a problem.

So I want to have a quick way for my Mac to do this for me. I imagine something like a script that extracts track numbers from file names or name tags through use of wildcard characters and applies them to respective ID3 tags while removing numbers from names. Finder has a handy built-in dialog for batch-renaming, but as far as I know it doesn't have this specific formatting functionality. I tried Automator and MusicBrainz Picard, but they don't have that either.

Is there anything that can be of help? Script libraries for Automator or Terminal commands? Maybe some handy AppleScript functions I don't know of?

Best Answer

A Combination of AppleScript (or Shell Scripting if you are so inclined), along with a command line tool like id3v2 should do the trick.

You can build id3v2 from source: http://id3v2.sourceforge.net Or use MacPorts or HomeBrew to do the building and installation for you.

Once you have it installed you can view the help page by typing in "id3v2 ah" from the terminal. The help page is more helpful than the man page is.

Then it is just a matter of writing the AppleScript to pass the filenames into variables and use those variables on the command line script like such:

set shellScript to ("id3v2 -T " & trackNumber & space & numberofTracks & space & "/path/to/file") as string
do shell script shellScript

You may also want to think about changing the name of the file itself so that it no longer has the track number in the name!

I hope this can get you started!