Windows SDK 的 iTunes COM 中的媒体类型
我最近发现了 iTunes COM for Windows SDK 的强大功能。我正在使用 Python 和 win32com 来与我的 iTunes 库对话。不用说,我的头快要爆炸了。这个 API 非常棒。
不过,我有一个问题,如何访问曲目的 Media Kind 属性?我查看了 SDK 中提供的帮助文件,但没有看到任何迹象。如果您进入 iTunes,您可以修改曲目的媒体类型。这样,如果您的音乐库中显示有有声读物,您可以将“媒体类型”设置为“有声读物”,它将显示在 iTunes 的“图书”部分中。非常漂亮。
我问的原因是因为我的 LibraryPlaylist 中显示了大量有声读物。
到目前为止,这是我的代码。
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?'
提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可能无法找到它的原因之一是 com 对象引用的原子结构可能已过时。 MP4 结构中最流行的原子列表如下: http://atomicparsley.sourceforge.net /mpeg-4files.html 我没有看到媒体类型的原子。我想你可以尝试通过atomicparsley解析结构,但据我所知,它只找到它知道的原子。
简短回答:COM 对象可能不知道 MediaKind 属性。
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.
我能找到的“Media Kind”属性的唯一参考是 ITUserPlaylistSpecialKind 枚举。唯一使用的地方是 getter 方法 IITUserPlaylist::SpecialKind。所以看起来这是一个只读的播放列表级属性。我猜想,为了阅读它,您需要获取曲目的播放列表,然后获取播放列表的 SpecialKind 属性。为了写入它,您可能必须将曲目移动到适当的播放列表。
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.
嗯,媒体种类位于接口 IITTrack.Kind 中,但这可能不是您想要的 - 答案将是以下之一:
可能您需要查看 IITTrack.Genre,给出 ID3 标签的字符串形式
流派,因此您可以找到“有声读物”或 Apple 的“Books & Spoken”。 (某些流派受到 iTunes/iPod 的特殊对待)。
提示:我下载的 iTunes SDK 中编译的帮助文件似乎已损坏 - 我必须将其转换回 HTML 文件并使用 Firefox/grep 来查找我需要的信息。
Well, the Media Kind is in interface IITTrack.Kind, but that probably isn't what you want - the answer will be one of:
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.
实际上很简单,使用 IITFileOrCDTrack.Podcast :
如果是播客,它将返回 True,否则将返回 False。
您当然可以通过它进行设置
很高兴我可以提供帮助。
It is actually quite easy, use the IITFileOrCDTrack.Podcast :
If it is a podcast, it will return True, otherwise it will return False.
You can of course set it through
Glad I could help.