mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-04-27 00:25:54 +03:00
[GH-ISSUE #277] sp.audio_features() not working correctly. Spotify updated endpoints? #151
Labels
No labels
api-bug
bug
dependencies
documentation
duplicate
enhancement
external-ide
headless-mode
implicit-grant-flow
invalid
missing-endpoint
pr-welcome
private-api
pull-request
question
spotipy3
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/spotipy#151
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @aalshukri on GitHub (Apr 22, 2018).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/277
Hi,
I have discovered that the function sp.audio_features() is not working correctly. This function currently returns nulls.
I think the problem relates to the endpoint in spotipy.
Minimal code example which returns nulls.
features = sp.audio_features(tid) print(json.dumps(features, indent=4))I have also tried the the example code:
features = sp.audio_features(tids) delta = time.time() - start for feature in features: print(json.dumps(feature, indent=4)) print() analysis = sp._get(feature['analysis_url']) print(json.dumps(analysis, indent=4)) print() print ("features retrieved in %.2f seconds" % (delta,))Reference: https://github.com/plamere/spotipy/blob/master/examples/audio_features.py
The above example failed because "sp._get(feature['analysis_url'])" does not return any JSON results (it returned nulls as mentioned) which causes an exception.
What I expected from this function was a list of features as shown below:
{ "danceability": 0.696, "energy": 0.905, "key": 2, "loudness": -2.743, "mode": 1, "speechiness": 0.103, "acousticness": 0.011, "instrumentalness": 0.000905, "liveness": 0.302, "valence": 0.625, "tempo": 114.944, "type": "audio_features", "id": "11dFghVXANMlKmJXsNCbNl", "uri": "spotify:track:11dFghVXANMlKmJXsNCbNl", "track_href": "https://api.spotify.com/v1/tracks/11dFghVXANMlKmJXsNCbNl", "analysis_url": "https://api.spotify.com/v1/audio-analysis/11dFghVXANMlKmJXsNCbNl", "duration_ms": 207960, "time_signature": 4 }Reference: https://beta.developer.spotify.com/console/get-audio-features-track/
The functionality can be replicated using the spotify web console
GET https://api.spotify.com/v1/audio-features/{id}Thanks for your help
Ash
@shatteringlass commented on GitHub (Aug 5, 2018):
I can confirm this. Possibly I'll submit a PR.
EDIT: strangely enough, the current implementation works for string arguments but not lists. I was able to fetch audio features for a comma separated string of track IDs. There seems to be nothing wrong in the else branch of the function code.
@lyons7 commented on GitHub (Sep 19, 2018):
Did this ever get fixed? I couldn't even get the comma separated string of track IDs work-around to work!
@eribradl commented on GitHub (Oct 3, 2018):
I just ran into this same issue today, and it looks to me like audio_features('something') is expecting 'something' to be a list. Similarly, the response you get back is also a list.
@aalshukri To make your first example work, try:
features = sp.audio_features(tid)[0]
@Brakjen commented on GitHub (May 7, 2019):
I am not getting this to work either. It returns a list of None. However, I can get the features if I set up my own get request using requests, and json to parse the output. The function below could be made more sophisticated to accept lists of track ids, and not a single id. Just pass your token and track id as kwargs.
@paarmann commented on GitHub (Feb 6, 2020):
Works as expected in spotipy=2.7.1
Returns:
The result list may contain Null values if there are no audio features available for the id at this position.
@stephanebruckert commented on GitHub (Feb 9, 2020):
Thanks for the feedback @paarmann, gonna close this one
@anushkacodez commented on GitHub (Feb 13, 2025):
Hi this doesn't work anymore. Is there any other way to get audio features in python?
@dieser-niko commented on GitHub (Feb 13, 2025):
No, you're somewhat late to the party. Please check #1172