by

Fixing Total Tracks and Removing Album Artist in iTunes

iTunes seems to have a bug if you edit the album artists on an album, it blows away the total number of tracks for a song. I had a bunch of songs that had album artists for half the tracks in the album but not the others, which cased all sorts of havoc when trying to play an album since iTunes can’t figure out the order to play them in any more.

I wrote up a little script to remove the Album Arist and also to fix up any places where the total number of tracks for a song is incorrect. It looks at the other tracks for the album to find what the correct total should be, so it’s only useful if at least one track in the album has the correct total.

I put the script up on Pastie, http://pastie.caboo.se/72537, and also below. It’s not the fastest thing, but it works (for me). Use at your own risk, I’m not responsible, yadda yadda yadda.

var   iTunesApp = WScript.CreateObject("iTunes.Application");
var   mainLibrary = iTunesApp.LibraryPlaylist;
var   tracks = mainLibrary.Tracks;
var   i;
var allAlbumsToArtist = new Array();
var allAlbumsToTrackCount = new Array();
 

for (i = 1; i <= tracks.Count; i++)
{

        var   currTrack = tracks.Item(i);
        allAlbumsToArtist[currTrack.Album] = currTrack.Artist;

        if(currTrack.TrackCount > 0)
        {
                allAlbumsToTrackCount[currTrack.Album] = currTrack.TrackCount;
        }

}

for (i = 1; i <= tracks.Count; i++)
{
        var currTrack = tracks.Item(i);
        WScript.Echo ("removing album aritst for  " + currTrack.Name);
        currTrack.AlbumArtist = "";
}

for (i = 1; i <= tracks.Count; i++)
{
        var   currTrack = tracks.Item(i);
        if(!(currTrack.TrackCount > 0))
        {
                var totalTracks = allAlbumsToTrackCount[currTrack.Album];
                if(totalTracks > 0)
                {
                        WScript.Echo ("changing  " + currTrack.Name + " to total tracks " + totalTracks);                
                        currTrack.TrackCount = totalTracks;
                }
        }
}