diff --git a/spotifyvis/views.py b/spotifyvis/views.py index 5a4ee80..b1154f9 100644 --- a/spotifyvis/views.py +++ b/spotifyvis/views.py @@ -116,4 +116,33 @@ def user_data(request): 'user_name': user_data_response['display_name'], 'id': user_data_response['id'], } - return render(request, 'spotifyvis/user_data.html', context) \ No newline at end of file + return render(request, 'spotifyvis/user_data.html', context) + + + +def get_features(track_id, token): + """Returns the features of a soundtrack + + Args: + track_id: the id of the soundtrack, needed to query the Spotify API + token: an access token for the Spotify API + + Returns: + A dictionary with the features as its keys + """ + + headers = { + 'Authorization': token, + } + response = requests.get("https://api.spotify.com/v1/audio-features/{}".format(track_id), headers = headers).json() + features_dict = {} + + # Data that we don't need + useless_keys = [ + "key", "mode", "type", "liveness", "id", "uri", "track_href", "analysis_url", "time_signature", + ] + for key, val in response.items(): + if key not in useless_keys: + features_dict[key] = val + + return features_dict \ No newline at end of file