2016-04-30 3 views
3

Я хочу, чтобы мой Echonestresponse получил song duration, который предположительно входит в состав audio_summary.Echonest :: продолжительность песни

params = { 
     'type':'artist-radio', 
     'artist':artist, 
     'results': 3, 
     'bucket' : ['id:spotify-WW', 'tracks'], 
     'limit': True 
    } 
    response = en.get('playlist/static', **params) 
    songs = response['songs'] 

так, чтобы получить песню duration, который key/value я должен использовать в приведенном выше примере?

ПРИМЕЧАНИЕ: оболочка используется в pyen

ответ

0

duration является анализ нашел в song/profile, а не в playlist/static методе, поэтому нам нужен второй response из api.

это один из способов получения каждой песни duration (а также печать artist_name и song_title):

#get 'playlist response' 
    response_playlist = en.get('playlist/static', **params) 
    song_playlist = response_playlist['songs'] 

    if len(song_playlist) > 0: 

     for i, song in enumerate(song_playlist): 
      #we need to track each song id 
      song_id = song_playlist[i]['id'] #ok 
      #in order to get song 'duration', we need to access 'song/profile response' 
      #and pass the id as an argument to 'audio_summary' 
      response_profile = en.get('song/profile', id=song_id, bucket="audio_summary") 
      song_profile = response_profile['songs'] 
      dur = song_profile[0]['audio_summary']['duration']  
      print dur       
      #now we access each song 'foreign_id', which is playable by, say, Spotify 
      for track in song: 
       track = song['tracks'][i] 
       track_id = track['foreign_id'].replace('-WW', '')   
      print '{0} {2} {1}'.format(i, song['artist_name'], song['title']) 
Смежные вопросы