Restoring Play Count data from the XML Music Library file
The week before last week I had a kernel crash which destroyed my iTunes 4 Music Library file (cut it in half). Norton was unable to recover it or a complete temp file so I figured I was lost. I had almost setteled with a backup from June when I realized the XML (which was intact) includes Rating, Play Count and Last Played information (the only stuff I really cared about restoring). Unfortunately, iTunes, for some strange reason, is only capable of importing the Rating value of those three. Knowing how to artificially increase the play count I figured an AppleScript could do it. I was in fact directed to this AppleScript at Doug's AppleScripts for iTunes (http://www.malcolmadams.com/itunes/scripts/scripts09.shtml#increaseplaycount) . However, that script didn't actually solve the problem since manually adding the play count to each track would be an immense task. Also, it came without source ;) so I couldn't modify it either.
Instead, I decied to learn AppleScript myself and do what's needed. While my AppleScript skills weren't sufficient to do it in AppleScript alone I did manage to restore my Play Counts (Last played still remains unimported and not as important) using a combination of Shell srcipting, Perl and AppleScript. Confusing as it may sound, it works, which is really everything it has to do.
Now since I did get some useful tips form this forum and elsewhere, I think it would be unfair to keep the script for myself. So feel free to download 'iTunesPlayCountImporter' (http://www.niksula.cs.hut.fi/~jkrogell/ipci.tar) (StuffIt will open that just fine, naturally, tar -xf ipci.tar will also do the trick). It's GPL (http://www.gnu.org/licenses/licenses.html#GPL) if anyone is intrested.
Let me know if you actually use it.
Also, if anyone knows a faster way to add play counts than with 'delay 1' then please tell me.
[1932 byte] By [
mwaf] at [2007-11-9 13:11:08]

# 1 Re: Restoring Play Count data from the XML Music Library file
Hello mwaf,
Your package sounds great. I'll check it out. I'm very interested in the shell-AppleScript-Perl connection. Thanks for letting us know about it.
By the way, you are probably right about using Increase Play Count on an entire library; but as far as the source goes, it is easily obtained by opening the script in Script Editor. Did you have a problem with it?
# 2 Re: Restoring Play Count data from the XML Music Library file
Originally posted by Doug Adams
but as far as the source goes, it is easily obtained by opening the script in Script Editor. Did you have a problem with it?
:o hehe... seems so, I didn't realize that. I probably just open it in BBEdit and since that didn't make any sense so I figured it was compiled and couldn't do anything about it.
Well, I manged to open it now and it was nice seeing how you did it. Isn't there any way to have a delay less than 1 second?
mwaf at 2007-11-15 17:26:13 >

# 3 Re: Restoring Play Count data from the XML Music Library file
You could try using a positive real number for the delay. I've only gotten down to .6 to work. Here's the test I used:
repeat with i from 1 to 4
beep
delay 0.6
end repeat
The thing is: the "played count" won't increase unless the track has been played from start to finish, which is why the finish property is set as short as possible (start + 1) and why the delay must "cover" it.
Know what I mean?
# 4 Re: Restoring Play Count data from the XML Music Library file
Well I used:
set player position to (get finish of current track)
...which eliminates the problem of having to cover one second.
The delay only has to be long enough for iTunes to 'get to the next track' before the loop has got to "set player position to (get finish of current track)" again.
Originally I had no 'delay' at all, but it just kept jumping to 'finish' the required amount of times before iTunes got around to finish the track.
Now i tried it with 0.6 and it worked. (Nothing less seemed to work, though.) So that should reduce the time it takes to complete the whole library to 60% of the original (going down from my six hours to litle over three and half hours).
Anyways, anyone who tries IPCI might want to change line 41 in the ipci_increasePlayCounts file to "delay 0.6"
mwaf at 2007-11-15 17:28:13 >

# 5 Re: Restoring Play Count data from the XML Music Library file
Originally posted by mwaf
Originally I had no 'delay' at all, but it just kept jumping to 'finish' the required amount of times before iTunes got around to finish the track.
Yes, that's the problem I ran in to. Glad to see you got .6 to work (sort of odd, isn't it?). I'll have to update Increase Play Count (http://www.malcolmadams.com/itunes/scripts/scripts09.shtml#increaseplaycount).