mirror of
https://github.com/c0de-archive/spotipy.git
synced 2024-11-05 07:27:47 +00:00
Adapted to new audio_features response
This commit is contained in:
parent
38ea4b6910
commit
9c0b872e86
@ -633,7 +633,13 @@ class Spotify(object):
|
|||||||
- tracks - a list of track URIs, URLs or IDs, maximum: 50 ids
|
- tracks - a list of track URIs, URLs or IDs, maximum: 50 ids
|
||||||
'''
|
'''
|
||||||
tlist = [self._get_id('track', t) for t in tracks]
|
tlist = [self._get_id('track', t) for t in tracks]
|
||||||
return self._get('audio-features?ids=' + ','.join(tlist))
|
results = self._get('audio-features?ids=' + ','.join(tlist))
|
||||||
|
# the response has changed, look for the new style first, and if
|
||||||
|
# its not there, fallback on the old style
|
||||||
|
if 'audio_attributes' in results:
|
||||||
|
return results['audio_attributes']
|
||||||
|
else:
|
||||||
|
return results
|
||||||
|
|
||||||
def _get_id(self, type, id):
|
def _get_id(self, type, id):
|
||||||
fields = id.split(':')
|
fields = id.split(':')
|
||||||
|
@ -173,6 +173,24 @@ class AuthTestSpotipy(unittest.TestCase):
|
|||||||
self.assertTrue(playlist['tracks']['total'] == 3)
|
self.assertTrue(playlist['tracks']['total'] == 3)
|
||||||
self.assertTrue(len(playlist['tracks']['items']) == 3)
|
self.assertTrue(len(playlist['tracks']['items']) == 3)
|
||||||
|
|
||||||
|
def test_audio_features(self):
|
||||||
|
results = spotify.audio_features(self.four_tracks)
|
||||||
|
self.assertTrue(len(results) == len(self.four_tracks))
|
||||||
|
for attr in results:
|
||||||
|
assert('speechiness' in attr)
|
||||||
|
|
||||||
|
def test_audio_features_with_bad_track(self):
|
||||||
|
bad_tracks = ['spotify:track:bad']
|
||||||
|
input = self.four_tracks + bad_tracks
|
||||||
|
results = spotify.audio_features(input)
|
||||||
|
self.assertTrue(len(results) == len(input))
|
||||||
|
none_count = 0
|
||||||
|
for attr in results:
|
||||||
|
if attr == None:
|
||||||
|
none_count +=1
|
||||||
|
else:
|
||||||
|
assert('speechiness' in attr)
|
||||||
|
self.assertTrue(none_count == len(bad_tracks))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
|
Loading…
Reference in New Issue
Block a user