Spotipy - 跟踪名称和能量值

时间:2016-08-09 03:29:28

标签: python list spotipy

def lowEnergy():

    tids = []
    # get songs by recommendation
    results = sp.recommendations(seed_artists = [artist['id']])

    #retrieve uris for songs
    for track in results['tracks']:
        tids.append(track['uri'])

    #get audio_features
    features = sp.audio_features(tids)

    #pick energies
    energy = [x['energy'] for x in features]

    #here I filter out low energy values
    low_energy = [x for x in energy if x < 0.5]

    #get track names
    track_names = [sp.track(uri)['name'] for uri in tids]

现在我想按照0.5 以下的能量值过滤掉曲目名称,如下所示:

track name1 - 0.49 track name2 - 0.34

等等。

但我在这里挣扎......我怎么做到这一点?感谢

1 个答案:

答案 0 :(得分:0)

未经测试,但希望它有效。

for i, e in enumerate(energy):
    if e < 0.5:
        track_name = sp.track(tids[i])['name']
        print("{} - {}".format(track_name, e))