Mencari film, buku, dan podcast dengan Python

Paket podsearch untuk menemukan podcast



Apple tidak benar-benar mengiklankan bahwa iTunes Store dan direktori lain memiliki API pencarian yang sederhana tetapi sederhana - jadi saya memutuskan untuk menulis tentang hal itu. Dari pos ini Anda akan mempelajari apa yang dapat dilakukan API dan bagaimana menggunakannya.



Pencarian Direktori Apple



API mencari konten dari iTunes Store, iBooks Store, Apple Podcasts, dan App Store. Dengan demikian, Anda dapat menemukan lagu, film, buku, podcast, dan aplikasi.



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).
  • Tidak ada pola respons.
  • Apple membatasi panggilan API hingga 20 permintaan per menit.


Deskripsi API pada Paket Pencarian Podcast Apple



Jika Anda menginginkan hal-hal yang lebih menarik dengan Python - berlangganan saluran @ohmypy




All Articles