将 HEX iTunes 持久 ID 转换为高位和低位 32 位形式

发布于 2024-10-14 06:45:35 字数 843 浏览 2 评论 0原文

在 Mac 上,我可以从“iTunes Music Library.xml”文件中提取特定歌曲的“持久 ID”,然后使用 Applescript 播放该歌曲,如下所示:

tell application "iTunes"   
    set thePersistentId to "F040658A7687B12D"
    set theSong to (some track of playlist "Music" whose persistent ID is thePersistentId)  
    play theSong with once  
end tell  

在 PC 上,我可以从以下位置提取“持久 ID” : XML 文件以同样的方式。 iTunes COM 接口的文档称函数“ItemByPercientId”有两个参数:“highID”(64 位持久 ID 的高 32 位)和“lowID”(64 位持久 ID 的低 32 位) 。但我不知道如何将基于十六进制的值转换为 ItemByPersistentId 函数所需的高位和低位 32 位值。

var thePersistentId = "F040658A7687B12D";  
var iTunes = WScript.CreateObject("iTunes.Application"); 
var n = parseInt(thePersistentId);  
var high = (do something with n?);  
var low = (do something else with n?);  
iTunes.LibraryPlaylist.tracks.ItemByPersistentId(high,low).play();  

On a Mac, I can extract the "Persistent ID" for a particular song from the "iTunes Music Library.xml" file and then use Applescript to play that song like so:

tell application "iTunes"   
    set thePersistentId to "F040658A7687B12D"
    set theSong to (some track of playlist "Music" whose persistent ID is thePersistentId)  
    play theSong with once  
end tell  

On a PC, I can extract the "Persistent ID" from the XML file in the same way. The documentation for the iTunes COM interface says the function "ItemByPersistentId" has two parameters: "highID" (The high 32 bits of the 64-bit persistent ID) and "lowID" (The low 32 bits of the 64-bit persistent ID). but I can't figure out how to convert the hex-based value to the high and low 32-bit values the ItemByPersistentId function wants.

var thePersistentId = "F040658A7687B12D";  
var iTunes = WScript.CreateObject("iTunes.Application"); 
var n = parseInt(thePersistentId);  
var high = (do something with n?);  
var low = (do something else with n?);  
iTunes.LibraryPlaylist.tracks.ItemByPersistentId(high,low).play();  

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉城 2024-10-21 06:45:35

我不知道windows脚本主机上的情况是什么,但是有些JS客户端有32位int,所以你的 var n = parseInt(thePercientId); 就加倍麻烦了。使用 parseInt 时应始终包含基数(例如 parseInt(hexValue, 16)parseInt(octValue, 8))。

为了避免 32 位脚本解释器的限制,您可以分别提取低 32 位和高 32 位。每个十六进制数字都是 4 位,因此低 32 位是持久 ID 的最后 8 个字符,高 32 位是剩余的 8 个字符(除非它具有 0x 前缀,那么它是下一个最右边的 8 个字符块)。

var hexId = "XXXXX";   
var iTunes = WScript.CreateObject("iTunes.Application");  

//the following two statements assume you have a valid 64 bit hex, 
//you may want to verify the length of the string

//grab and parse the last 8 characters of your string
var low = parseInt(hexId.substr(hexId.length - 8), 16);
//grab and parse the next last 8 characters of your string
var high = parseInt(hexId.substr(hexId.length - 16, 8), 16);
iTunes.LibraryPlaylist.tracks.ItemByPersistentId(high,low).play(); 

编辑:从我在 iTuner源代码,看起来highID实际上是高4个字节,而lowID是低4个字节,而不是8个字节(因此丢弃了中间的8个字节) persistentID 的字节...)。这是一个修改后的尝试:

//assumes hex strings with no "0x" prefix
//grab and parse the last 4 characters of your string
var low = parseInt(hexId.substr(hexId.length - 4), 16);
//grab, pad and parse the first 4 characters of your string
var high = parseInt(hexId.substr(0, 4) + "0000", 16);

I don't know what the situation is on the windows script host, but some JS clients have a 32 bit int, so your var n = parseInt(thePersistentId); is doubly troublesome. You should always include the base when using parseInt (e.g. parseInt(hexValue, 16), parseInt(octValue, 8)).

To avoid 32 bit script interpreter limitations, you can extract the lower 32 bits and upper 32 bits seperately. Each hex digit is 4 bits, so the lower 32 bits are the last 8 characters of your persistent ID, and the upper 32 bits are the remaining 8 (unless it has the 0x prefix, then it's the next rightmost chunk of 8 characters).

var hexId = "XXXXX";   
var iTunes = WScript.CreateObject("iTunes.Application");  

//the following two statements assume you have a valid 64 bit hex, 
//you may want to verify the length of the string

//grab and parse the last 8 characters of your string
var low = parseInt(hexId.substr(hexId.length - 8), 16);
//grab and parse the next last 8 characters of your string
var high = parseInt(hexId.substr(hexId.length - 16, 8), 16);
iTunes.LibraryPlaylist.tracks.ItemByPersistentId(high,low).play(); 

Edit: From what I've read in the iTuner source code, it looks like highID is actually the upper 4 bytes, and lowID the lower 4 bytes, not 8 bytes (thus discarding the middle 8 bytes of the persistentID...). Here's a modified attempt:

//assumes hex strings with no "0x" prefix
//grab and parse the last 4 characters of your string
var low = parseInt(hexId.substr(hexId.length - 4), 16);
//grab, pad and parse the first 4 characters of your string
var high = parseInt(hexId.substr(0, 4) + "0000", 16);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文