我正在编写一个音乐引用应用程序,并且对于每张专辑(从 last.fm 中提取)都希望链接到 ITMS(如果专辑在商店中)。
iTunes 链接制作网络工具 http://apple.com/itunes/linkmaker/非常适合获取已知专辑的链接,但我需要从我的应用程序内以编程方式访问它。
这个NSLog blogpost这是从 2003 年开始的,但是是 referenced more recently in another question here似乎提供了迄今为止我遇到的唯一解决方案,建议将查询提交至:
phobos.apple.com/WebObjects/MZSearch.woa/wa/advancedSearchResults?
Put "itms://" before it and the link will work in iTunes, put "http://" before it and the link will work in Camino (Safari sometimes spits back a malformed XML error).
The tags that are of importance are as follows:
- songTerm - song title
- artistTerm - artist name
- albumTerm - album name
- composerTerm - composer name
- term - all fields
建议使用 http://而不是 itms://,服务器将返回结果的 XML 文档,而不是打开 iTunes,但无论哪种方式,我都会直接发送到 iTunes。
是否可以获取结果列表?
最佳答案
我正在使用 LinkMaker 获取有关我正在播放的歌曲的 iTunes 详细信息。 为此,我发现 LinkMaker 能够返回 json 数据,并且一次返回 1 个结果。
我正在使用此网址来执行我的查询:
以下是您需要提供的参数:
> country : store country term : could
> contains artist name, song name, album
> media : music
例如,如果您想了解“U2”的一首名为“One”的歌曲的详细信息,这里是正确的 URL:
然后你会收到这样的json数据:
{
"resultCount":1,
"results": [
{"wrapperType":"track", "mediaType":"song", "artistName":"U2", "itemParentName":"Achtung Baby", "itemParentCensoredName":"Achtung Baby", "itemCensoredName":"One", "itemName":"One", "artistLinkUrl":"http://itunes.apple.com/us/artist/u2/id78500?uo=4", "artworkUrl60":"http://a1.phobos.apple.com/us/r1000/009/Features/32/9a/60/dj.mfynlttx.60x60-50.jpg", "artworkUrl100":"http://a1.phobos.apple.com/us/r1000/009/Features/32/9a/60/dj.mfynlttx.100x100-75.jpg", "country":"USA", "currency":"USD", "discCount":1, "discNumber":1, "itemExplicitness":"notExplicit", "itemLinkUrl":"http://itunes.apple.com/us/album/one/id368713?i=368617&uo=4", "itemPrice":"1.29000", "itemParentExplicitness":"notExplicit", "itemParentLinkUrl":"http://itunes.apple.com/us/album/one/id368713?i=368617&uo=4", "itemParentPrice":"9.99000", "previewUrl":"http://a1.phobos.apple.com/us/r1000/019/Music/b6/8c/c5/mzm.epegonxg.aac.p.m4a", "primaryGenreName":"Rock", "trackCount":12, "trackNumber":3, "trackTime":276042}]
}
然后您需要解码这些 JSON 数据。
NSDictionary *jsonResultsParsed = [jsonResults JSONValue];
最终得到你想要的:
NSDictionary *songDetailsDict = [[jsonResultsParsed objectForKey:@"results"] objectAtIndex:0];
如果您想确定用户的国家/地区,您需要使用其区域设置来确定其国家/地区,这是我正在使用的代码:
- (NSString *)getUserCountry
{
NSLocale *locale = [NSLocale currentLocale];
return [locale objectForKey: NSLocaleCountryCode];
}
希望这有帮助。
蒂埃里
编辑:终于有一个文档可用了:
关于iphone - iTunes Music Store Link Maker — 如何在我的应用程序中进行搜索?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2639684/