search endpoint
上的,可以检索playlist
数据,例如:
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'}
但我如何访问跟踪 NAMES ,因为此id
的{{1}}代表endpoint
而不是playlist
自己?
答案 0 :(得分:1)
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)