Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed audio_features API wrapper function return structure #653

Merged
merged 2 commits into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## Unreleased [3.0.0-alpha]

While this is unreleased, please only add v3 features here.
Rebasing master onto v3 doesn't require a changelog update.

### Added

- ...
### Changed
Modified the return structure of the `audio_features` function (wrapping the [Get Audio Features for Several Tracks](https://developer.spotify.com/documentation/web-api/reference/#endpoint-get-several-audio-features) API) to conform to the return structure of similar APIs, such as:
- [Get Several Tracks](https://developer.spotify.com/documentation/web-api/reference/#endpoint-get-several-tracks)
- [Get Multiple Artists](https://developer.spotify.com/documentation/web-api/reference/#endpoint-get-multiple-artists)
- [Get Multiple Albums](https://developer.spotify.com/documentation/web-api/reference/#endpoint-get-multiple-albums)
The functions wrapping these APIs do not unwrap the single key JSON response, and this is currently the only function that does this.

## Unreleased [2.x.x]

Expand Down
7 changes: 1 addition & 6 deletions spotipy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1623,12 +1623,7 @@ def audio_features(self, tracks=[]):
else:
tlist = [self._get_id("track", t) for t in tracks]
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_features" in results:
return results["audio_features"]
else:
return results
return results

def devices(self):
""" Get a list of user's available devices.
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/test_non_user_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,19 @@ def test_audio_analysis(self):

def test_audio_features(self):
results = self.spotify.audio_features(self.four_tracks)
self.assertTrue(len(results) == len(self.four_tracks))
for track in results:
self.assertTrue(len(results['audio_features']) == len(self.four_tracks))
for track in results['audio_features']:
assert('speechiness' in track)

def test_audio_features_with_bad_track(self):
bad_tracks = ['spotify:track:bad']
input = self.four_tracks + bad_tracks
results = self.spotify.audio_features(input)
self.assertTrue(len(results) == len(input))
for track in results[:-1]:
self.assertTrue(len(results['audio_features']) == len(input))
for track in results['audio_features'][:-1]:
if track is not None:
assert('speechiness' in track)
self.assertTrue(results[-1] is None)
self.assertTrue(results['audio_features'][-1] is None)

def test_recommendations(self):
results = self.spotify.recommendations(
Expand Down