Spotify - 获取播放列表曲目名称

时间:2016-08-19 04:54:33

标签: python spotify spotipy

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自己?

非常感谢提前。

1 个答案:

答案 0 :(得分:1)

TypeScript decorators

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)