iTunes Music Store Link Maker — how to search from within my app?

前端 未结 2 719
予麋鹿
予麋鹿 2021-02-01 00:15

I\'m writing a music reference app and for each album (pulled from last.fm) would like to link to the ITMS (if the album is in the store).

iTunes link maker web tool http

2条回答
  •  走了就别回头了
    2021-02-01 00:38

    I am using LinkMaker to get iTunes details about song I am playing. For that, I found that LinkMaker is able to return json data and also 1 result at a time.

    I am using this url to perfom my query :

    http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStoreServices.woa/wa/itmsSearch?lang=1&output=json&country=%@&term=%@&media=%@&limit=1"

    Here are parameters you need to give :

    > country : store country term : could
    > contains artist name, song name, album
    > media : music
    

    For exemple, if you want to have details for a song called "One" by "U2" here is the correct URL :

    http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStoreServices.woa/wa/itmsSearch?lang=1&output=json&country=US&term=U2%20one&media=music&limit=1

    Then you will receive json data like this :

    {
     "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}]
    }
    

    You need then to decode these JSON data.

    NSDictionary *jsonResultsParsed = [jsonResults JSONValue];
    

    And finally get what you want :

    NSDictionary *songDetailsDict = [[jsonResultsParsed objectForKey:@"results"] objectAtIndex:0];
    

    If you want to determine user's country you will need to determine its country using its locale, here is the code I am using :

    - (NSString *)getUserCountry
    {
        NSLocale *locale = [NSLocale currentLocale];
        return [locale objectForKey: NSLocaleCountryCode];
    }
    

    Hope this helps.

    Thierry

    Edit: Finally a doc is available:

    http://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html

提交回复
热议问题