This tutorial will show you how to get the 30 second music preview using Apple's iTunes API. The goal of this is to help developers script a process for dynamically accessing data.
Step 1 - Pick a Track
As a starting point, let's pick a demo track. Visit Apple's iTunes link maker and select a track you want to preview. For this demo, I will use Tom Misch's "The Journey".
Your search result will end with a profile page with an embed code and direct link down below.
Step 2 - Find the Apple / iTunes ID (formerly Adam ID)
Almost every database assigns some sort of unique identifier to each track. For example, MusicBrainz uses mbid
, GraceNote uses musicid
and All Music uses amg
.
Apple Music/iTunes uses an identifier called adamid
. Sometimes newer documentation will call it an Apple ID or an iTunes ID.
iTunes Link Maker will provide you with an adamid
. All you need to do is copy and paste the final numbers at the end of any iTunes track.
For example, using the Link Maker tool above, this is the Direct Link for Tom Misch's "The Journey".
https://geo.itunes.apple.com/us/album/the-journey/id1023678446?i=1023678453&mt=1&app=music
The URL above contains two ID's.
1023678446
is the album ID.1023678453
is the track ID.
Note: If you want to learn which other identifiers the Apple Web Service API accepts, visit this document.
Step 3 - Lookup
Now that we have the unique ID to this specific song, we can now run an iTunes lookup to get the other bits of metadata such as Album Art and 30 second previews.
https://itunes.apple.com/us/lookup?id=1023678453
Step 4 - Parse Your Results
The iTunes lookup will give you all the metadata you need including the 30 second preview.
You can access the 30 second preview URL like this:
{
"resultCount": 1,
"results": [{
"wrapperType": "track",
"kind": "song",
"artistId": 893237941,
"collectionId": 1023678446,
"trackId": 1023678453,
"artistName": "Tom Misch",
"collectionName": "Beat Tape 2",
"trackName": "The Journey",
"collectionCensoredName": "Beat Tape 2",
"trackCensoredName": "The Journey",
"artistViewUrl": "https://music.apple.com/us/artist/tom-misch/893237941?uo=4",
"collectionViewUrl": "https://music.apple.com/us/album/the-journey/1023678446?i=1023678453&uo=4",
"trackViewUrl": "https://music.apple.com/us/album/the-journey/1023678446?i=1023678453&uo=4",
"previewUrl": "https://audio-ssl.itunes.apple.com/itunes-assets/Music7/v4/3a/a3/01/3aa30184-78e2-7030-c6e0-d33f3d3e21b7/mzaf_3396140578378232458.plus.aac.p.m4a",
"artworkUrl30": "https://is1-ssl.mzstatic.com/image/thumb/Music69/v4/09/e9/f9/09e9f9fb-ff71-59c4-d8fb-47cd51c65397/source/30x30bb.jpg",
"artworkUrl60": "https://is1-ssl.mzstatic.com/image/thumb/Music69/v4/09/e9/f9/09e9f9fb-ff71-59c4-d8fb-47cd51c65397/source/60x60bb.jpg",
"artworkUrl100": "https://is1-ssl.mzstatic.com/image/thumb/Music69/v4/09/e9/f9/09e9f9fb-ff71-59c4-d8fb-47cd51c65397/source/100x100bb.jpg",
"collectionPrice": 9.99,
"trackPrice": 1.29,
"releaseDate": "2015-08-28T12:00:00Z",
"collectionExplicitness": "notExplicit",
"trackExplicitness": "notExplicit",
"discCount": 1,
"discNumber": 1,
"trackCount": 12,
"trackNumber": 1,
"trackTimeMillis": 266820,
"country": "USA",
"currency": "USD",
"primaryGenreName": "Alternative",
"isStreamable": true
}]
}
Step 5 - Success!
That's it! You now have a process for accessing 30 second previews.
One thing to note, Apple has a 20req/min limit on the Search API. If you want to do more, you will need to become an affiliate partner and use the Enterprise Partner Feed
Resources
API
- Music API's is a list of music API's you might need to leverage to create the music app of your dreams.
Docs
- Apple Music API will ultimately replace a lot of the iTunes API documentation.
- iTunes search API is the dynamic way of searching and dynamically creating affiliate links.
- iTunes Search API Rules is a really important document. READ THIS!
- Enterprise Partner Feed is a lot more robust than the iTunes Search API.
- Apple PHG Affiliate Guidelines is great for helping you understand how to use marketing campaign variables to source your affiliate income.
- iTunes URL parameter cheat sheet for PHG affiliates is a great resource for helping explain all the params needed to submit a successful GET request.
- iTunes Store Collection (formerly iMix) can help you create an iMix, sell it and earn an affiliate fee. This is the closest thing you can use to help programmatically create an iTunes / Apple Music playlist.
Tools
- iTunes link maker - This helps you find the Adam ID on a single track.
- JSON Formatter is a Google Chrome extension that will make it much easier to read JSON within your browser.
- Yahoo YQL + iTunes queries can help developers create a proper web API that can execute without cross-domain origin errors. Yahoo YQL can also create a JSONP response.
Answers
- How to launch the app store from within my iOS app.
- How to run an iTunes query from within my iOS app.
itms://itunes.apple.com/WebObjects/MZStore.woa/wa/search
- Example: iTunes iMix Collection
Radio: How to submit your podcast to iTunes and Spotify
Sometimes you need to self-host your own Podcast files and feed. Here's how using Amazon Web Services.
Types of Digital Radio Apps
I've been working in radio for 7 years and over that time people, have asked me how many types of radio apps I can actually make....