views:

265

answers:

3

I recently found out about the awesomeness of the iTunes COM for Windows SDK. I am using Python with win32com to talk to my iTunes library. Needless to say, my head is in the process of exploding. This API rocks.

I have one issue though, how do I access the Media Kind attribute of the track? I looked through the help file provided in the SDK and saw no sign of it. If you go into iTunes, you can modify the track's media kind. This way if you have an audiobook that is showing up in your music library, you can set the Media Kind to Audiobook and it will appear in the Books section in iTunes. Pretty nifty.

The reason I ask is because I have a whole crap load of audiobooks that are showing up in my LibraryPlaylist.

Here is my code thus far.

import win32com.client

iTunes = win32com.client.gencache.EnsureDispatch('iTunes.Application')
track = win32com.client.CastTo(iTunes.LibraryPlaylist.Tracks.Item(1), 'IITFileOrCDTrack')

print track.Artist, '-', track.Name
print
print 'Is this track an audiobook?'
print 'How the hell should I know?'

Thanks in advance.

A: 

The only reference I can find to that "Media Kind" attribute is the ITUserPlaylistSpecialKind enum. The only place that is used is a getter method IITUserPlaylist::SpecialKind. So it seems that is a read-only playlist-level attribute. I would guess that in order to read it you need to get the playlist of the track and then get the playlists's SpecialKind attribute. In order to write it, you probably have to move the track to the appropriate playlist.

Luke
A: 

One reason why you may not be able to find it is that the atom structure the com object references may be out of date. The most popular list of atoms from the MP4 structure is here: http://atomicparsley.sourceforge.net/mpeg-4files.html I don't see a media kind atom. I suppose you could try to parse the structure through atomicparsley but to my knowledge it only finds atoms that it knows about.

Short Answer: The COM object may not know about the MediaKind Attribute.

DeanMc
A: 

Well, the Media Kind is in interface IITTrack.Kind, but that probably isn't what you want - the answer will be one of:

public enum ITTrackKind
    {
        ITTrackKindUnknown = 0,
        ITTrackKindFile = 1,
        ITTrackKindCD = 2,
        ITTrackKindURL = 3,
        ITTrackKindDevice = 4,
        ITTrackKindSharedLibrary = 5,
    }

Probably you need to look at IITTrack.Genre, which gives the string form of the ID3 tag Genre, so you can find "Audiobook" or Apple's "Books & Spoken". (Some genres are treated specially by iTunes/iPods).

Tip: the compiled help file in the ITunes SDK I downloaded seemed to be broken - I had to convert it back to HTML files and use Firefox/grep to find the information I needed.

MZB