marysolomon / KPOPThesis

1 stars 0 forks source link

'NoneType' object is not subscriptable at acousticness feature #2

Closed marysolomon closed 3 years ago

marysolomon commented 3 years ago

When calling audio features the following error occurred

line 51, in getTrackFeatures acousticness = features[0]['acousticness'] TypeError: 'NoneType' object is not subscriptable

marysolomon commented 3 years ago

Reason for error: the song is not available in any country's market. Can detect by using if statement on len(available_markets) == 0.

currently treating the issue with:

if len(available_markets) == 0: track = [uri, name, album, album_uri, artist, artist_uri, release_date, popularity, None, None, None, None, None, None, None, None, None, None, None, None, None] return track

Need to confirm that this works when appending to features list and then converting to a pandas dataframe.

marysolomon commented 3 years ago

Above code works for songs when no market available, however there is another cause for the error message: Audio features not available for that song at all. In JSON format the following is returned:

{ "error": { "status": 404, "message": "analysis not found" } }>

need to investigate how this is handled with spotipy/python

Error occurs for song number 4,759 with id: 5DwA51NBp0HmurkK0Pl9be album name: DJ Chullly's genuine masterpieces 4" song name: "Oh salvia - Bangsili"

additional problem: this album doesn't even feature artists that i'm searching for :(

marysolomon commented 3 years ago

This is how the python stores the features if there are none:

[None]

a NoneType audio feature for a given song is stored as a single valued list as seen above. To detect for nonetype audio features, use the following logical statement:

badsong = '5DwA51NBp0HmurkK0Pl9be' badmeta = sp.track(badsong) nofeature = sp.audio_features(badsong) if len(badmeta['available_markets']) == 0 or nofeature[0] == None: print('skip') else: print('it ok')

This is kept in the SpotifyAPI_Guide notebook.