mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-06-19 09:13:53 +00:00
Fixed audio_features API wrapper function return structure (#653)
Co-authored-by: Stéphane Bruckert <stephane.bruckert@gmail.com>
This commit is contained in:
parent
f3d1192c38
commit
f7ae328501
10
CHANGELOG.md
10
CHANGELOG.md
@ -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/),
|
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).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
|
||||||
## Unreleased [3.0.0-alpha]
|
## Unreleased [3.0.0-alpha]
|
||||||
|
|
||||||
While this is unreleased, please only add v3 features here.
|
While this is unreleased, please only add v3 features here.
|
||||||
Rebasing master onto v3 doesn't require a changelog update.
|
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]
|
## Unreleased [2.x.x]
|
||||||
|
|
||||||
|
|||||||
@ -1623,12 +1623,7 @@ class Spotify(object):
|
|||||||
else:
|
else:
|
||||||
tlist = [self._get_id("track", t) for t in tracks]
|
tlist = [self._get_id("track", t) for t in tracks]
|
||||||
results = 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
|
return results
|
||||||
# its not there, fallback on the old style
|
|
||||||
if "audio_features" in results:
|
|
||||||
return results["audio_features"]
|
|
||||||
else:
|
|
||||||
return results
|
|
||||||
|
|
||||||
def devices(self):
|
def devices(self):
|
||||||
""" Get a list of user's available devices.
|
""" Get a list of user's available devices.
|
||||||
|
|||||||
@ -67,19 +67,19 @@ class AuthTestSpotipy(unittest.TestCase):
|
|||||||
|
|
||||||
def test_audio_features(self):
|
def test_audio_features(self):
|
||||||
results = self.spotify.audio_features(self.four_tracks)
|
results = self.spotify.audio_features(self.four_tracks)
|
||||||
self.assertTrue(len(results) == len(self.four_tracks))
|
self.assertTrue(len(results['audio_features']) == len(self.four_tracks))
|
||||||
for track in results:
|
for track in results['audio_features']:
|
||||||
assert('speechiness' in track)
|
assert('speechiness' in track)
|
||||||
|
|
||||||
def test_audio_features_with_bad_track(self):
|
def test_audio_features_with_bad_track(self):
|
||||||
bad_tracks = ['spotify:track:bad']
|
bad_tracks = ['spotify:track:bad']
|
||||||
input = self.four_tracks + bad_tracks
|
input = self.four_tracks + bad_tracks
|
||||||
results = self.spotify.audio_features(input)
|
results = self.spotify.audio_features(input)
|
||||||
self.assertTrue(len(results) == len(input))
|
self.assertTrue(len(results['audio_features']) == len(input))
|
||||||
for track in results[:-1]:
|
for track in results['audio_features'][:-1]:
|
||||||
if track is not None:
|
if track is not None:
|
||||||
assert('speechiness' in track)
|
assert('speechiness' in track)
|
||||||
self.assertTrue(results[-1] is None)
|
self.assertTrue(results['audio_features'][-1] is None)
|
||||||
|
|
||||||
def test_recommendations(self):
|
def test_recommendations(self):
|
||||||
results = self.spotify.recommendations(
|
results = self.spotify.recommendations(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user