I'm getting the tracks of some albums from lastfm. Then for each track I'm getting some information (title, number, artist, etc). Then, I want also to get the mbid of each track, but here I have an error:
Get and store tracks information from albums is working fine:
<Response [200]>
print(track_mbid_response) returns on this format
{"track":{"name":"Brown Sugar","mbid":"8d2338a2-4acc-4d99-b2a7-1151f428cab6","url":"https://www.last.fm/music/The+Rolling+Stones/_/B...
KeyError: 'mbid'
.Get and store tracks information from albums is working fine:
tracks = {} for i, v in albums.items(): artist = albums[i]['artist'].replace(" ", "+") name = albums[i]['name'].replace(" ", "+") album_response_data = requests.get( 'http://ws.audioscrobbler.com/2.0/?method=album.getinfo&format=json&api_key=' + api_key + '&artist=' + artist + '&album=' + name) album_response = album_response_data.json() if 'album' in album_response.keys(): for album in album_response['album']['tracks']['track']: title = album['name'] tracks[ID] = {} tracks[ID]['trackID'] = ID tracks[ID]['title'] = title tracks[ID]['number'] = number tracks[ID]['artist'] = albums[i]['artist'] tracks[ID]['album'] = albums[i]['name'] tracks[ID]['albumID'] = albums[i]['ID'] ID += 1Then getting and store the mbid of each track is where the issue is:
for i, v in tracks.items(): artist = tracks[i]['artist'].replace(" ", "+") title = tracks[i]['title'].replace(" ", "+") track_mbid = requests.get('http://ws.audioscrobbler.com/2.0/?method=track.getInfo&format=json&api_key=' + api_key + '&artist=' + artist + '&track=' + title) track_mbid_response = track_mbid.json() #print(track_mbid_response.keys()) #print(track_mbid_response) track_data = track_mbid_response["track"] #for track in track_data: #print(track) mbid = track_data['mbid'] tracks[i]['mbid'] = mbid print(tracks)print(track_mbid):
<Response [200]>
print(track_mbid_response) returns on this format
{"track":{"name":"Brown Sugar","mbid":"8d2338a2-4acc-4d99-b2a7-1151f428cab6","url":"https://www.last.fm/music/The+Rolling+Stones/_/B...