mirror of
https://github.com/agresdominik/predictify.git
synced 2026-04-21 09:51:56 +00:00
Unified spotify api request into one function
This commit is contained in:
@@ -40,34 +40,6 @@ def get_track_information(track_id: str, bearer_token: str) -> dict:
|
||||
return response_json
|
||||
|
||||
|
||||
def get_multiple_tracks_information(bearer_token: str, *track_ids) -> dict:
|
||||
"""
|
||||
This function returns the track information based on the track id
|
||||
|
||||
:param *track_id: str
|
||||
:param bearer_token: str
|
||||
:return: dict
|
||||
"""
|
||||
if len(track_ids) > 50:
|
||||
log.error('Passed more than 50 track ids to get_multiple_tracks_information')
|
||||
return None
|
||||
|
||||
url_suffix = "ids="
|
||||
separator = ","
|
||||
for track_id in track_ids:
|
||||
url_suffix = url_suffix + track_id + separator
|
||||
|
||||
url = f"https://api.spotify.com/v1/tracks?{url_suffix}"
|
||||
url = url[:-len(separator)]
|
||||
header = {
|
||||
'Authorization': f'Bearer {bearer_token}'
|
||||
}
|
||||
|
||||
response = requests.get(url, headers=header)
|
||||
response_json = response.json()
|
||||
return response_json
|
||||
|
||||
|
||||
def get_artist_information(artist_id: str, bearer_token: str) -> dict:
|
||||
"""
|
||||
This function returns the artist information based on the artist id
|
||||
|
||||
Reference in New Issue
Block a user