iTunes持久性ID - 音乐库xml版本和iTunes十六进制版本 [英] itunes persistent id - music library xml version and iTunes hex version

查看:172
本文介绍了iTunes持久性ID - 音乐库xml版本和iTunes十六进制版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从ItunesMusicLibrary.xml中读取一个十六进制PersistentID字符串,得到两个代表高位和低位32位的整数,然后在iTunes脚本中使用这两个整数。



不幸的是,ItunesMusicLibrary.xml中的持久ID字符串在iTunes中似乎不是一样的持久ID,可以通过各种脚本接口访问。



iTunes音乐library.xml包含一个64位密钥Persistent ID。例如,

 < key>持久ID< / key><字串> 0F1610959DA92DAB< / string> ;. 

您也可以使用Windows COM接口通过脚本获取PersistentID。例如,

  iTunes.ITObjectPersistentIDHigh(track) - > 253104277 

iTunes.ITObjectPersistentIDLow(track) - > -1649857109

如果我将这两个数字反馈回iTunes,我会得到正确的曲目

  iTunes.LibraryPlaylist.Tracks.ItemByPersistentID(253104277,-1649857109).Name 

我的问题是将xml库中的十六进制字符串转换为高位和低位整数。例如,在python

  int('0F1610959DA92DAB'[:8],16) - > 253104277 
int('0F1610959DA92DAB'[8:],16) - > 2645110187

第一个是正确的,第二个不是。如果我将这两个值反馈回iTunes,它不起作用。使用其他曲目,有时两个数字都是错误的。



知道怎么回事以及如何解决它?

解决方案

您将数字解释为未签名,但iTunes正在使用signed。 2645110187与-1649857109相同。你可能想要这样的东西:

  struct.unpack('!i',binascii.a2b_hex('0F1610959DA92DAB'[8: ]))[0] 

...或者同时获取两个值:

  struct.unpack('!ii',binascii.a2b_hex('0F1610959DA92DAB'))

...它为您提供所需的元组:

 (253104277,-1649857109)


I'd like to read a hex PersistentID string from ItunesMusicLibrary.xml, get two ints representing the high and low 32 bits, then use those two ints in an iTunes script.

Unfortunately, the Persistent ID string in ItunesMusicLibrary.xml does not seem to be the same Persistent ID that's in itunes, as accessible through various scripting interfaces

itunes music library.xml includes a 64 bit key, Persistent ID. For example,

<key>Persistent ID</key><string>0F1610959DA92DAB</string>.

You can also get the PersistentID through a script using the windows COM interface. For example,

iTunes.ITObjectPersistentIDHigh(track) -> 253104277

iTunes.ITObjectPersistentIDLow(track) -> -1649857109

If I feed those two numbers back into iTunes, I get the correct track

iTunes.LibraryPlaylist.Tracks.ItemByPersistentID(253104277,-1649857109).Name

My problem is translating the hex string from the xml library to high and low integers

For example, in python

int('0F1610959DA92DAB'[:8], 16) -> 253104277
int('0F1610959DA92DAB'[8:], 16) -> 2645110187

The first is correct, the second is not. If I feed the two values back into iTunes, it doesn't work. Using other tracks, sometimes both numbers are wrong.

Any idea what's going on and how to fix it?

解决方案

You're interpreting the numbers as unsigned but iTunes is using signed. 2645110187 is the same as -1649857109. You might want something like this:

struct.unpack('!i', binascii.a2b_hex('0F1610959DA92DAB'[8:]))[0]

...or get both values in one go:

struct.unpack('!ii', binascii.a2b_hex('0F1610959DA92DAB'))

...which gives you the tuple you need:

(253104277, -1649857109)

这篇关于iTunes持久性ID - 音乐库xml版本和iTunes十六进制版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆