CoverArtProvider.queue_downloads() -> queue_images()

- provide compatibility with existing plugins using queue_downloads()
This commit is contained in:
Laurent Monin
2015-07-01 17:07:14 +02:00
parent 20b3f198e7
commit 03baf8ec67
5 changed files with 19 additions and 14 deletions

View File

@@ -130,7 +130,7 @@ class CoverArt:
p = provider(self)
if p.enabled():
log.debug("Trying cover art provider %s ..." % name)
ret = p.queue_downloads()
ret = p.queue_images()
else:
log.debug("Skipping cover art provider %s ..." % name)
except:
@@ -177,7 +177,7 @@ class CoverArt:
def queue_put(self, coverartimage):
"Add an image to queue"
log.debug("Queing %r for download", coverartimage)
log.debug("Queuing cover art image %r", coverartimage)
self.__queue.append(coverartimage)
def _queue_get(self):

View File

@@ -35,12 +35,12 @@ def cover_art_providers():
class CoverArtProvider:
"""Subclasses of this class need to reimplement at least `queue_downloads()`.
"""Subclasses of this class need to reimplement at least `queue_images()`.
`__init__()` does not have to do anything.
`queue_downloads()` will be called if `enabled()` returns `True`.
`queue_downloads()` must return `FINISHED` when it finished to queue
`queue_images()` will be called if `enabled()` returns `True`.
`queue_images()` must return `FINISHED` when it finished to queue
potential cover art downloads (using `queue_put(<CoverArtImage object>).
If `queue_downloads()` delegates the job of queuing downloads to another
If `queue_images()` delegates the job of queuing downloads to another
method (asynchronous) it should return `WAIT` and the other method has to
explicitely call `next_in_queue()`.
If `FINISHED` is returned, `next_in_queue()` will be automatically called
@@ -49,10 +49,10 @@ class CoverArtProvider:
# default state, internal use
_STARTED = 0
# returned by queue_downloads():
# returned by queue_images():
# next_in_queue() will be automatically called
FINISHED = 1
# returned by queue_downloads():
# returned by queue_images():
# next_in_queue() has to be called explicitely by provider
WAIT = 2
@@ -65,10 +65,15 @@ class CoverArtProvider:
def enabled(self):
return True
def queue_downloads(self):
def queue_images(self):
# this method has to return CoverArtProvider.FINISHED or
# CoverArtProvider.WAIT
raise NotImplementedError
old = getattr(self, 'queue_downloads') #compat with old plugins
if callable(old):
old()
log.warning('CoverArtProvider: queue_downloads() was replaced by queue_images()')
else:
raise NotImplementedError
def error(self, msg):
self.coverart.album.error_append(msg)
@@ -77,7 +82,7 @@ class CoverArtProvider:
self.coverart.queue_put(what)
def next_in_queue(self):
# must be called by provider if queue_downloads() returns WAIT
# must be called by provider if queue_images() returns WAIT
self.coverart.next_in_queue()
def match_url_relations(self, relation_types, func):

View File

@@ -96,7 +96,7 @@ class CoverArtProviderAmazon(CoverArtProvider):
return False
return not self.coverart.front_image_found
def queue_downloads(self):
def queue_images(self):
self.match_url_relations(('amazon asin', 'has_Amazon_ASIN'),
self._queue_from_asin_relation)
return CoverArtProvider.FINISHED

View File

@@ -118,7 +118,7 @@ class CoverArtProviderCaa(CoverArtProvider):
def _caa_path(self):
return "/release/%s/" % self.metadata["musicbrainz_albumid"]
def queue_downloads(self):
def queue_images(self):
self.album.tagger.xmlws.download(
CAA_HOST,
CAA_PORT,

View File

@@ -42,7 +42,7 @@ class CoverArtProviderWhitelist(CoverArtProvider):
return False
return not self.coverart.front_image_found
def queue_downloads(self):
def queue_images(self):
self.match_url_relations(('cover art link', 'has_cover_art_at'),
self._queue_from_whitelist)
return CoverArtProvider.FINISHED