Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
def tr_md(track_id):
#returns a list of desired track metadata from track_id
track_info = sp.track(track_id)
#track metadata
track_id = track_info['id'] #redundant, but easier to keep track of this way.
track_name = track_info['name']
track_length = track_info['duration_ms']
track_preview_url = track_info['preview_url']
track_number = track_info['track_number']
track_href = track_info['href']
track_external_urls = track_info['external_urls']['spotify']
track_external_id_isrc = track_info['external_ids']['isrc']
album_id = track_info['album']['id']
album_name = track_info['album']['name']
album_href = track_info['album']['href']
album_ext_url = track_info['album']['external_urls']['spotify']
album_release_date = track_info['album']['release_date']
album_release_date_precision = track_info['album']['release_date_precision']
album_total_tracks = track_info['album']['total_tracks']
album_type = track_info['album']['type']
album_image_large = track_info['album']['images'][0]['url']
album_image_medium = track_info['album']['images'][1]['url']
album_image_small = track_info['album']['images'][2]['url']
artist_id = track_info['album']['artists'][0]['id']
artist_name = track_info['album']['artists'][0]['name']
artist_href = track_info['album']['artists'][0]['href']
artists_ext_url = track_info['album']['artists'][0]['external_urls']['spotify']
track_data = [track_id, track_name, album_id, album_name,
artist_id, artist_name, track_preview_url,
track_number, track_href, track_external_urls,
track_external_id_isrc, album_href, album_ext_url,
album_release_date, album_release_date_precision,
album_total_tracks, album_type, album_image_large,
album_image_medium, album_image_small, artist_href,
artists_ext_url]
return track_data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment