From 87a4e8cb48cef17362d5d2dea7eea7265f53666a Mon Sep 17 00:00:00 2001 From: Sebastian Bischoff Date: Mon, 2 Jan 2017 14:57:48 +0100 Subject: [PATCH] Add fetching of audio features of one song --- spotipy/client.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/spotipy/client.py b/spotipy/client.py index 0d13fa0..7b9527f 100644 --- a/spotipy/client.py +++ b/spotipy/client.py @@ -809,12 +809,16 @@ class Spotify(object): return self._get('audio-analysis/' + trid) def audio_features(self, tracks=[]): - ''' Get audio features for multiple tracks based upon their Spotify IDs + ''' Get audio features for one or multiple tracks based upon their Spotify IDs Parameters: - tracks - a list of track URIs, URLs or IDs, maximum: 50 ids ''' - tlist = [self._get_id('track', t) for t in tracks] - results = self._get('audio-features?ids=' + ','.join(tlist)) + if isinstance(tracks, str): + trackid = self._get_id('track', tracks) + results = self._get('audio-features/?ids=' + trackid) + 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: