0

I've got lots of CDs which were tagged and then imported into iTunes in the following format:

  • Cream Classics (disc 1)
  • Cream Classics (disc 2)
  • Cream Classics (disc 3)

What I would like to do is set the disc number of each of the albums (as iTunes has meta-data for this) and then rename the album to just "Cream Classics".

Given the number of albums I have, this is a horribly laborious manual process.

Whilst I could knock up something in vbscript to do it automatically, I'm hoping that this was a common enough issue for someone to have already solved the problem.

Any suggestions?

1
  • Without going the full yard with something like Musicbrainz Picard and retagging your entire library once and for all, the best (most accurate) option is likely to do it yourself manually. Commented Dec 15, 2013 at 19:33

1 Answer 1

0

It turns out that writing vbscript to fix it wasn't that hard at all.

Create a new text file with the name fixdisc.vbs and put the following into it:

Option Explicit
Dim oiTunes : Set oiTunes = CreateObject("iTunes.Application")
Dim oLibrary : Set oLibrary = oiTunes.LibraryPlaylist
Dim oTracks : Set oTracks = oLibrary.Tracks
Dim i, oSong, p, sDisk, sNewTitle, iTotal
iTotal = oTracks.Count
For i = 1 To iTotal
    Set oSong = oTracks.Item(i) 
    For p = 1 To 4
        sDisk = " (disc " & p & ")"
        If Instr(1, oSong.Album, sDisk, vbTextCompare) > 0 Then
            sNewTitle = Replace(oSong.Album, sDisk, "", 1, -1, vbTextCompare)
            WScript.Echo i & "/" & iTotal & ": Setting '" & oSong.Album & "' to '" & sNewTitle & "' and disk number to " & p
            ' Remove the ' prefix on the next two lines to actually update the data!
            ' oSong.DiscNumber = p
            ' oSong.Album = sNewTitle
            Exit For
        End If
    Next
Next
Set oSong = Nothing
Set oTracks = Nothing
Set oLibrary = Nothing
Set oiTunes = Nothing

Bring up a command prompt (using cmd), navigate to the location of the script and type:

cscript fixdisc.vbs

The script will tell you what albums it will change but will not make the changes. When you're happy, edit the script and remove the ' from the two lines so the code looks like this:

            ' Remove the ' prefix on the next two lines to actually update the data!
            oSong.DiscNumber = p
            oSong.Album = sNewTitle
            Exit For
        End If

Now re-run the script and any tracks containing (disc x) (where x is 1 to 4) will have the appropriate "Disc Number" meta-data populated and the album title will be updated to remove that string.

Caveats/warnings

  • If you double click it from Windows, then you'll get spammed with pop-ups. So always run from the command line.
  • I've not fully tested it, use at your own risk! (backup your library first)
  • Only "disc x" will work, you can easily tweak it to support "disk x" if you want.
  • Only disc numbers 1 to 4 will work, you can easily tweak it to do more.
  • Complex disc numbers (eg. "Northern Exposure (disc 1: 0 degrees, north)") will not be corrected.
  • It takes quite a long time to do and your iTunes library will jump around erratically as the data is corrected. Your PC gets a little bogged down too.

Enjoy.

1
  • Worth noting that this script isn't the best way to do this. Anyone who wants to rewrite this should consider forcing the script to run as cscript, checking for the presence of (dis first in the string and then using a regular expression (such as \(dis[ck] (\d+).*?\) to extract the disc number. This will result in no need to use the command line, faster processing, support for "disk/disc" variants, support for any disc number and support for complex disc numbers. So basically, most of the caveats!
    – Richard
    Commented Dec 19, 2013 at 22:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .