Mit Python nach Filmen, BĂŒchern und Podcasts suchen

Podsearch-Paket zum Auffinden von Podcasts



Apple wirbt nicht wirklich dafĂŒr, dass der iTunes Store und andere Verzeichnisse ĂŒber eine krumme, aber einfache Such-API verfĂŒgen. Deshalb habe ich beschlossen, darĂŒber zu schreiben. In diesem Beitrag erfahren Sie, was die API kann und wie sie verwendet wird.



Apple-Verzeichnissuche



Die API durchsucht Inhalte aus dem iTunes Store, dem iBooks Store, Apple Podcasts und dem App Store. Dementsprechend finden Sie Songs, Filme, BĂŒcher, Podcasts und Anwendungen.



Die API arbeitet nach dem lĂ€ngst vergessenen JSONP- Prinzip , dh sie kehrt Content-Type: text/javascriptanstelle des normalen zurĂŒck 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).
  •  .
  • Apple API 20  .


API-Beschreibung auf dem Podcast-Suchpaket der Apple-Website



Wenn Sie weitere interessante Dinge in Python möchten, abonnieren Sie den @ ohmypy- Kanal




All Articles