4

I want to integrate Apple Music into my app, however I don’t want people to have to log in to Apple Music. I just want to get the preview tracks of songs.

Is that possible?

Bhavesh Nayi
  • 3,626
  • 1
  • 27
  • 42
Tometoyou
  • 7,792
  • 12
  • 62
  • 108

1 Answers1

8

It is possible to use the Apple Music API to retrieve a song's 30-second preview without the user needing to log in.

  1. Get a developer token

  2. Issue a request for a song

  3. Parse the response to get a Song previews URL

  4. Playback the song with a streaming media player (e.g. Howler)

Example with cURL:

curl -X GET \
  'https://api.music.apple.com/v1/catalog/us/search?term=drake&types=songs&limit=1' \
  -H 'Authorization: Bearer eyJhbG...'
{
    "results": {
        "songs": {
            "href": "/v1/catalog/us/search?limit=5&term=drake&types=songs",
            "next": "/v1/catalog/us/search?offset=5&term=drake&types=songs",
            "data": [
                {
                    "id": "1384782182",
                    "type": "songs",
                    "href": "/v1/catalog/us/songs/1384782182",
                    "attributes": {
                        "previews": [
                            {
                                "url": "https://audio-ssl.itunes.apple.com/apple-assets-us-std-000001/AudioPreview125/v4/f5/bc/9e/f5bc9e9c-d62b-332b-04c4-061018d060fc/mzaf_7200764193324270096.plus.aac.p.m4a"
                            }
                        ]
...

You can play the preview using the browser if you want to:

https://audio-ssl.itunes.apple.com/apple-assets-us-std-000001/AudioPreview125/v4/f5/bc/9e/f5bc9e9c-d62b-332b-04c4-061018d060fc/mzaf_7200764193324270096.plus.aac.p.m4a

roman
  • 537
  • 2
  • 5
  • Hey can I ask how you created the developer token? I’m having trouble actually getting authorised. – Tometoyou May 19 '19 at 09:57
  • Hopefully answered your [question](https://stackoverflow.com/questions/56208428/401-error-when-accessing-musickit-api-via-node-js/56209716#56209716) – roman May 19 '19 at 16:21