diff --git a/maloja/thirdparty/__init__.py b/maloja/thirdparty/__init__.py index 9c3e670..7c582d0 100644 --- a/maloja/thirdparty/__init__.py +++ b/maloja/thirdparty/__init__.py @@ -10,6 +10,7 @@ import xml.etree.ElementTree as ElementTree import json import urllib.parse, urllib.request import base64 +import time from doreah.logging import log from threading import BoundedSemaphore @@ -196,6 +197,8 @@ class MetadataInterface(GenericInterface,abstract=True): "activated_setting":None } + delay = 0 + # service provides this role only if the setting is active AND all # necessary auth settings exist def active_metadata(self): @@ -219,6 +222,7 @@ class MetadataInterface(GenericInterface,abstract=True): else: imgurl = None if imgurl is not None: imgurl = self.postprocess_url(imgurl) + time.sleep(self.delay) return imgurl def get_image_artist(self,artist): @@ -234,6 +238,7 @@ class MetadataInterface(GenericInterface,abstract=True): else: imgurl = None if imgurl is not None: imgurl = self.postprocess_url(imgurl) + time.sleep(self.delay) return imgurl def get_image_album(self,album): @@ -251,6 +256,7 @@ class MetadataInterface(GenericInterface,abstract=True): else: imgurl = None if imgurl is not None: imgurl = self.postprocess_url(imgurl) + time.sleep(self.delay) return imgurl # default function to parse response by descending down nodes diff --git a/maloja/thirdparty/deezer.py b/maloja/thirdparty/deezer.py index 0a9243b..9fa426c 100644 --- a/maloja/thirdparty/deezer.py +++ b/maloja/thirdparty/deezer.py @@ -19,6 +19,8 @@ class Deezer(MetadataInterface): "required_settings": [], } + delay = 1 + def get_image_track(self,track): return None # we can use the album pic from the track search, @@ -29,4 +31,9 @@ class Deezer(MetadataInterface): if result.get('data') == []: return True if result.get('error',{}).get('code',None) == 4: + self.delay += 1 + # this is permanent (for the lifetime of the process) + # but that's actually ok + # since hitting the rate limit means we are doing this to fast + # and these requests arent really time sensitive raise RateLimitExceeded()