Add send_art event for embedart and thumbnails

Album.set_art() sends a 'art_sent' event, with the album as a
parameter. embedart and thumbnails listen to that event, instead of
listening to 'album imported'. Consequences:
- 'embedart' and 'thumbnails' don't have to be after 'fetchart' on the
  plugins config line.
- embedart and thumbnails work event when a "beets fetchart" command is
  issued.
- if another plugin ever set art then embedart and thumbnails will "just
  work" with it.
This commit is contained in:
Bruno Cauet 2015-01-31 13:55:13 +01:00
parent 0a37c4652e
commit a72ae5991f
3 changed files with 9 additions and 8 deletions

View file

@ -960,6 +960,8 @@ class Album(LibModel):
"""Sets the album's cover art to the image at the given path. """Sets the album's cover art to the image at the given path.
The image is copied (or moved) into place, replacing any The image is copied (or moved) into place, replacing any
existing art. existing art.
Sends an 'art_set' event with `self` as the sole argument.
""" """
path = bytestring_path(path) path = bytestring_path(path)
oldart = self.artpath oldart = self.artpath
@ -983,6 +985,8 @@ class Album(LibModel):
util.move(path, artdest) util.move(path, artdest)
self.artpath = artdest self.artpath = artdest
plugins.send('art_set', album=self)
def store(self): def store(self):
"""Update the database with the album information. The album's """Update the database with the album information. The album's
tracks are also updated. tracks are also updated.

View file

@ -53,7 +53,7 @@ class EmbedCoverArtPlugin(BeetsPlugin):
self._log.warning(u"ImageMagick 6.8.7 or higher not installed; " self._log.warning(u"ImageMagick 6.8.7 or higher not installed; "
u"'compare_threshold' option ignored") u"'compare_threshold' option ignored")
self.register_listener('album_imported', self.album_imported) self.register_listener('art_set', self.process_album)
def commands(self): def commands(self):
# Embed command. # Embed command.
@ -106,10 +106,10 @@ class EmbedCoverArtPlugin(BeetsPlugin):
return [embed_cmd, extract_cmd, clear_cmd] return [embed_cmd, extract_cmd, clear_cmd]
def album_imported(self, lib, album): def process_album(self, album):
"""Automatically embed art into imported albums. """Automatically embed art after art has been set
""" """
if album.artpath and self.config['auto']: if self.config['auto']:
max_width = self.config['maxwidth'].get(int) max_width = self.config['maxwidth'].get(int)
self.embed_album(album, max_width, True) self.embed_album(album, max_width, True)

View file

@ -52,7 +52,7 @@ class ThumbnailsPlugin(BeetsPlugin):
self.write_metadata = None self.write_metadata = None
if self.config['auto'] and self._check_local_ok(): if self.config['auto'] and self._check_local_ok():
self.register_listener('album_imported', self.imported) self.register_listener('art_set', self.process_album)
def commands(self): def commands(self):
thumbnails_command = Subcommand("thumbnails", thumbnails_command = Subcommand("thumbnails",
@ -68,9 +68,6 @@ class ThumbnailsPlugin(BeetsPlugin):
return [thumbnails_command] return [thumbnails_command]
def imported(self, lib, album):
self.process_album(album)
def process_query(self, lib, opts, args): def process_query(self, lib, opts, args):
self.config.set_args(opts) self.config.set_args(opts)
if self._check_local_ok(): if self._check_local_ok():