import requests
from pprint import pprint
spotify_get_current_track_url = 'https://api.spotify.com/v1/me/player'
spotify_access_token = 'xxx'
def get_current_track(access_token):
response = requests.get(
spotify_get_current_track_url,
headers={
"Authorization": f"Bearer {access_token}"
}
)
resp_json = response.json()
track_name = resp_json['item']['name']
artists = resp_json['item']['artists']
artists_names = ', '.join([artist['name'] for artist in artists])
current_track_info = {
"Название": track_name,
"Исполнители": artists_names
}
return current_track_info
def main():
current_track_info = get_current_track(
spotify_access_token
)
pprint(current_track_info, indent=8)
if __name__ == '__main__':
main()