Apple doesnβt really advertise that the iTunes Store and other directories have a crooked but simple search API - so I decided to write about it. From this post you will learn what the API can do and how to use it.
Search Apple Directories
The API searches content from the iTunes Store, iBooks Store, Apple Podcasts, and App Store. Accordingly, you can find songs, movies, books, podcasts and apps.
API JSONP, Content-Type: text/javascript
application/json
.
GET /search?media=podcast&term=python HTTP/1.1
Host: itunes.apple.com
Accept: application/json
HTTP/2 200
content-type: text/javascript; charset=utf-8
{...}
, :
import requests
def search(term, media):
url = "https://itunes.apple.com/search"
payload = {"term": term, "media": media}
response = requests.get(url, params=payload)
response.raise_for_status()
results = response.json().get("results", [])
return results
>>> results = search("python", media="podcast")
>>> results[0]["collectionName"]
'Talk Python To Me'
:
term
β , ;media
β (movie
,podcast
,music
,audiobook
,software
,ebook
,all
),all
;country
β , ISO- (us
,ru
, ...),us
;limit
β ,50
.
, :
import requests
def search(term, media="all", country="us", limit=10):
url = "https://itunes.apple.com/search"
payload = {"term": term, "media": media, "country": country, "limit": limit}
response = requests.get(url, params=payload)
response.raise_for_status()
results = response.json().get("results", [])
return results
:
{
"resultCount": 10,
"results": [
{
"wrapperType": "track",
"kind": "song",
"artistId": 1495668306,
"collectionId": 527039271,
"trackId": 527039276,
"artistName": "Dodge & Fuski",
"collectionName": "Never Say Die (Deluxe Edition)",
"trackName":"Python",
...
},
{
"wrapperType": "track",
"kind": "podcast",
"collectionId": 979020229,
"trackId": 979020229,
"artistName": "Michael Kennedy (@mkennedy)",
"collectionName": "Talk Python To Me"
...
},
...
]
}
(kind
) , . :
artistId
β ;artistName
β ;artistViewUrl
β Apple;collectionId
β ;collectionName
β ;collectionViewUrl
β Apple;trackId
β ;trackName
β ;artworkUrl100
β 100x100 ;country
β ;primaryGenreName
β .
β podsearch, .
(artistId
, collectionId
, trackId
), lookup
:
import requests
def lookup(object_id):
url = "https://itunes.apple.com/lookup"
payload = {"id": object_id}
response = requests.get(url, params=payload)
response.raise_for_status()
results = response.json().get("results", [])
return results
>>> results = lookup(979020229)
>>> results[0]["collectionName"]
'Talk Python To Me'
Content-Type . :
- (
country
) , . ISO- (ru
), β (RUS
). - The response pattern does not exist.
- Apple limits the frequency of API calls to 20 requests per minute.
API Description on Apple
Podcast Search Package
If you want more interesting things in Python - subscribe to @ohmypy channel