Skip to content

Commit

Permalink
lyrics: Tolerate empty Google response (#2437)
Browse files Browse the repository at this point in the history
  • Loading branch information
sampsyo committed Feb 13, 2017
1 parent 8087e82 commit 0a4709f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions beetsplug/lyrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,11 +564,17 @@ def fetch(self, artist, title):
urllib.parse.quote(query.encode('utf-8')))

data = self.fetch_url(url)
data = json.loads(data)
if not data:
self._log.debug(u'google backend returned no data')
return None
try:
data = json.loads(data)
except ValueError as exc:
self._log.debug(u'google backend returned malformed JSON: {}', exc)
if 'error' in data:
reason = data['error']['errors'][0]['reason']
self._log.debug(u'google lyrics backend error: {0}', reason)
return
self._log.debug(u'google backend error: {0}', reason)
return None

if 'items' in data.keys():
for item in data['items']:
Expand Down

0 comments on commit 0a4709f

Please sign in to comment.