beetbox / pyacoustid

Python bindings for Chromaprint acoustic fingerprinting and the Acoustid Web service
MIT License
332 stars 66 forks source link

'artists' key does not always exist #11

Closed sdobz closed 12 years ago

sdobz commented 12 years ago

In acoustid.py line 224: if recording['artists']:

generates a KeyError if there is no artist returned?

The results table is given here: {u'id': u'cd7a97ce-bdd8-4e7e-9399-b8d02ffc15a2'}

I changed it to: if 'artists' in recording:

Since the result also did not have a title I had to add the lines: if 'title' in recording: title = recording['title'] else: title = None

As well as change the return to: yield score, recording['id'], title, artist_name

and it seems to be working.

sampsyo commented 12 years ago

The above is a slightly different fix, using dict.get.