2016-08-19 42 views
0

search endpoint,一個可以檢索playlist數據,例如:Spotify的 - 獲得播放列表曲目名稱

def search_playlist(): 

    results = sp.search(q='doom metal', type='playlist') 

如果添加到代碼:

items = results['playlists']['items'][0]['tracks'] 
    print (items) 

我得到:

{u'total': 349, u'href': u'https://api.spotify.com/v1/users/handiofiblood/playlists/71CdtOFANPpdboCh6e8lHr/tracks'}我如何進入trackNAMES,考慮到這個endpoint代表的是playlist而不是tracks本身?

非常感謝提前。

回答

0

https://github.com/plamere/spotipy/blob/master/examples/user_playlists_contents.py

def show_tracks(results): 
for i, item in enumerate(tracks['items']): 
    track = item['track'] 
    print(" %d %32.32s %s" % (i, track['artists'][0]['name'], track['name'])) 

playlists = sp.user_playlists(username) 
    for playlist in playlists['items']: 
     if playlist['owner']['id'] == username: 
      print() 
      print(playlist['name']) 
      print(' total tracks', playlist['tracks']['total']) 
      results = sp.user_playlist(username, playlist['id'], fields="tracks,next") 
      tracks = results['tracks'] 
      show_tracks(tracks) 
      while tracks['next']: 
       tracks = sp.next(tracks) 
       show_tracks(tracks)