diff --git a/spotipy/client.py b/spotipy/client.py index dbd51d2..87ac29d 100644 --- a/spotipy/client.py +++ b/spotipy/client.py @@ -633,7 +633,13 @@ class Spotify(object): - tracks - a list of track URIs, URLs or IDs, maximum: 50 ids ''' 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): fields = id.split(':') diff --git a/tests/authtests.py b/tests/authtests.py index 6d4f9bb..9352b16 100644 --- a/tests/authtests.py +++ b/tests/authtests.py @@ -173,6 +173,24 @@ class AuthTestSpotipy(unittest.TestCase): self.assertTrue(playlist['tracks']['total'] == 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 len(sys.argv) > 1: