Need an explanation on iTunes COM persistent ID. Is the ID for a track same when its transferred to an iPod?

1.4k views Asked by At

I am writing a JScript script with iTunes COM api for updating ratings and played count from the iPod database back into iTunes Library. In order to do so, the script should be able to recognize the songs that were transferred from this iTunes Library, so that it can read the ratings data for the track on iPod and update the corresponding track in the iTunes Library

Here's the code I've written:

var iTunesApp = WScript.createObject("iTunes.Application");
var mainLibrary = iTunesApp.LibraryPlaylist;
var iPodLibraryPlaylist = playlists.Item(1);    // get the main iPod Library playlist(leaving the unimportant portion)

for(j=0; j <= iPodLibraryPlaylist.Tracks.Count - 1; j++) {
        foo = iPodLibraryPlaylist.Tracks.Item(j+1);    // j+1, coz this index is 1-based (why apple...why?)
        bar = mainLibrary.Tracks.ItemByPersistentID(iTunesApp.ITObjectPersistentIDHigh(foo), iTunesApp.ITObjectPersistentIDLow(foo));
        WScript.StdOut.WriteLine(bar.Name);    // should print the name of the track, but throws runtime error: Object required
}

According to the iTunes COM API

You can retrieve a source, playlist, or track with a specified persistent ID using the ItemByPersistentID property of the appropriate collection interface

ItemByPersistentID returns an IITTrack object with the specified persistent ID

Now the questions are:

  1. Am I right in saying that the 64-bit Persistent ID for a track in iTunes Library remains the same when the track is transferred to an iPod.
  2. Is there anything wrong in the way i'm using the ITObjectPersistentIDHigh() and ITObjectPersistentIDLow()
  3. Is there any totally other way to do this?

PS: There are 662 songs on the test iPod, so there's no problem there

Any help is much appreciated! thnx!

2

There are 2 answers

0
Doug On

If you have the latest nano, and turn on the voiceover function, then the ID changes, otherwise it doesn't. I'm trying to figure out how the SW knows to update the play count and time when you sync, since the ID isn't the same.

0
KVolker On

I do not think that there is only one other way of doing it, very long: compare, for each track in the iPod, the names, albums, lengths, etc with the one you have on your library. However, I don't think that will be a very effective solution, just an "easy to program" one.

I used the persistentID just like you did (although on a playlist). It should work... Maybe you should set the parameter as an int...