我知道你发布这个问题已经有一段时间了,但我遇到了同样的问题并且能够解决这个问题。iTunes 商店 trackId 存储在 iTunes 匹配文件的下载版本中。如果从文件中获取前 1024 个字节的数据,则轨道 id 是字符串 'song' 之后的前 4 个字节的数据。您需要将其从带符号的 32 位整数转换为十进制。
示例:没有汽车走(街机火灾)
file_string = File.open(path, 'r').read(1024)
index = file_string.index('song')
@iTunes_id = file_string[index+4,4].unpack('N')[0]
print "Song ID: #{@iTunes_id}"
结果是:
Song ID: 81607936
现在,您可以使用该 ID 并从 iTunes 中查找曲目数据:
https://itunes.apple.com/lookup?id=81607936&country=US
结果是:
{
"resultCount":1,
"results": [
{"wrapperType":"track", "kind":"song", "artistId":23203991, "collectionId":81607965, "trackId":81607936, "artistName":"Arcade Fire", "collectionName":"Arcade Fire EP", "trackName":"No Cars Go", "collectionCensoredName":"Arcade Fire EP", "trackCensoredName":"No Cars Go", "artistViewUrl":"https://itunes.apple.com/us/artist/arcade-fire/id23203991?uo=4", "collectionViewUrl":"https://itunes.apple.com/us/album/no-cars-go/id81607965?i=81607936&uo=4", "trackViewUrl":"https://itunes.apple.com/us/album/no-cars-go/id81607965?i=81607936&uo=4", "previewUrl":"http://a644.phobos.apple.com/us/r1000/060/Music2/v4/ba/95/be/ba95be41-4a03-4dea-2965-57dd5f0b66c0/mzaf_6092501386391248238.m4a", "artworkUrl30":"http://a5.mzstatic.com/us/r30/Music/y2005/m10/d01/h10/mzi.yfrupnuj.30x30-50.jpg", "artworkUrl60":"http://a2.mzstatic.com/us/r30/Music/y2005/m10/d01/h10/mzi.yfrupnuj.60x60-50.jpg", "artworkUrl100":"http://a5.mzstatic.com/us/r30/Music/y2005/m10/d01/h10/mzi.yfrupnuj.100x100-75.jpg", "collectionPrice":6.93, "trackPrice":0.99, "releaseDate":"2005-01-10T08:00:00Z", "collectionExplicitness":"notExplicit", "trackExplicitness":"notExplicit", "discCount":1, "discNumber":1, "trackCount":7, "trackNumber":3, "trackTimeMillis":364071, "country":"USA", "currency":"USD", "primaryGenreName":"Alternative", "radioStationUrl":"https://itunes.apple.com/station/idra.81607936"}]
}
我希望这对 OP 或其他任何人有所帮助,我无法在其他任何地方找到此信息。