Echonest :: 歌曲时长
Echonest :: song duration
我希望我的 Echonest
response
得到 song duration
,这应该是 audio_summary
.
的一部分
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
duration
是 song/profile
中的分析,而不是 playlist/static
方法中的分析,因此我们需要 api
中的第二个 response
。
这是获取每首歌曲 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'])
我希望我的 Echonest
response
得到 song duration
,这应该是 audio_summary
.
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
duration
是 song/profile
中的分析,而不是 playlist/static
方法中的分析,因此我们需要 api
中的第二个 response
。
这是获取每首歌曲 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'])