mirror of
https://github.com/beetbox/beets.git
synced 2025-12-25 01:53:31 +01:00
Merge pull request #71 from zacharydenton/master
echonest_tempo plugin: Don't crash when Echo Nest API rate limit is exceeded.
This commit is contained in:
commit
85b62081e4
1 changed files with 11 additions and 3 deletions
|
|
@ -15,6 +15,7 @@
|
|||
"""Gets tempo (bpm) for imported music from the EchoNest API. Requires
|
||||
the pyechonest library (https://github.com/echonest/pyechonest).
|
||||
"""
|
||||
import time
|
||||
import logging
|
||||
from beets.plugins import BeetsPlugin
|
||||
from beets import ui
|
||||
|
|
@ -60,9 +61,16 @@ def get_tempo(artist, title):
|
|||
# Unfortunately, all we can do is search by artist and title. EchoNest
|
||||
# supports foreign ids from MusicBrainz, but currently only for artists,
|
||||
# not individual tracks/recordings.
|
||||
results = pyechonest.song.search(
|
||||
artist=artist, title=title, results=1, buckets=['audio_summary']
|
||||
)
|
||||
try:
|
||||
results = pyechonest.song.search(
|
||||
artist=artist, title=title, results=1, buckets=['audio_summary']
|
||||
)
|
||||
except pyechonest.util.EchoNestAPIError as e:
|
||||
if e.code == 3:
|
||||
# rate limit exceeded - wait 10 seconds and try again.
|
||||
time.sleep(10)
|
||||
return get_tempo(artist, title)
|
||||
|
||||
if len(results) > 0:
|
||||
return results[0].audio_summary['tempo']
|
||||
else:
|
||||
|
|
|
|||
Loading…
Reference in a new issue