How do I correct wrong iTunes play counts?

The play count in my iTunes library has somehow become incorrect. It shows some songs as never been played while I know that I have played them many times before. These songs do still have a "last played" date though.

Also, some songs are being listed as only played once, while I know they have been played multiple times.

I have an iPhone 4S, with iOS 6.0.1, iTunes 11. My PC is a VAIO running on Windows 7. I have a backup of my iTunes account. I think the problem started after I updated my iTunes account to version 11.

What I need is to get my original play count data back. Can anyone help me with this?


For minor play count screwups, I use a little AppleScript to set the count:

tell application "iTunes"
  activate
  set played count of track named "Vaseline Machine Gun" to 16
  return
end tell

Obviously this can be elaborated to handle more complicated situations involving multiple tracks and playlists.


There's a bug in iTunes 11 where the play count isn't updated if you have crossfading of tracks turned on in the playback settings. This might account for some of it.


Here's the real, heavy duty power solution:

Use Notepad to create a new file named: iTunes_SetPlayCount.VBS

Use this script:


Dim iTunesApp, selectedTracks, newPlayCount
Dim prompt, title, defaultValue

Set iTunesApp = WScript.CreateObject("iTunes.Application")
Set selectedTracks = iTunesApp.SelectedTracks

prompt = "New playcount:"

For Each IITTrack In selectedTracks
    title = IITTrack.Artist & " - " & IITTrack.Name
    defaultValue = IITTrack.PlayedCount
    newPlayCount = InputBox (prompt, title, defaultValue)

    'MsgBox("NewPlayCount = " & newPlayCount)

    If Len(newPlayCount) > 0 Then
        If IsNumeric(newPlayCount) Then
            If newPlayCount >= 0 Then 
                IITTrack.PlayedCount = newPlayCount
            End If
        End If
    Else
        Exit For
    End If
Next

KaaBAM!


Summary

If you quit iTunes and empty the contents of your iTunes Library.itl file, then iTunes will rebuild your library from the contents of iTunes Media Library.xml. Make sure it's up to date by exporting your library and copying the file, and then edit the play counts inside. When you restart iTunes, it will use the XML file and your edited information will be accepted.

Step-by-step

Retrieve previous information:

If you have backups of your iTunes library, find the most recent version of iTunes Media Library.xml from before the problem. Within this file, search for the songs whose play counts you want to restore. You'll be looking for this:

<key>Play Count</key><integer>1337</integer>

Now you know what the accurate play counts were. Copy and paste them into a text file or something so you can put them in your current library next.

Modify current library:

This is the tricky part, so back up your files before editing them.

  1. Use File > Library > Export Library… to get an up-to-date XML representation of your library. I'll refer to this file as Library.xml.

  2. Exit iTunes and use the Task Manager to make sure it (and the iTunes Helper) are well and truly dead.

  3. Navigate to your iTunes folder. Replace the contents of iTunes Media Library.xml and iTunes Library.xml with your newly created Library.xml. This will ensure that they're up to date.

  4. Change the play counts in the iTunes Media Library.xml file. This file is about to become the basis for your library's metadata.

  5. Remove the contents of your iTunes Library.itl file. The file itself needs to exist, but it must be empty so that iTunes will fall back to iTunes Media Library.xml. (more info) If everything works, you will not need the old contents of this file.

  6. Restart iTunes. It will report that your library is corrupted, so it will fall back to the XML file that you've edited and rebuild the .itl file. After it's finished, you'll see the play counts from iTunes Media Library.xml.


I haven't verified that there's absolutely no data loss with this method, but my library appeared fully intact when I tested it with iTunes 11 on OS X 10.8. Always back up your files before tweaking. Enjoy!