Merge pull request #1267 from mried/extractart-for-albums

Extractart for albums
This commit is contained in:
mried 2015-01-28 17:23:42 +01:00
commit d73a55cf19
3 changed files with 43 additions and 10 deletions

View file

@ -88,12 +88,30 @@ class EmbedCoverArtPlugin(BeetsPlugin):
help='extract an image from file metadata')
extract_cmd.parser.add_option('-o', dest='outpath',
help='image output file')
extract_cmd.parser.add_option('-n', dest='filename',
help='image filename to create for all '
'matched albums')
extract_cmd.parser.add_option('-a', dest='associate',
action='store_true',
help='associate the extracted images '
'with the album')
def extract_func(lib, opts, args):
outpath = normpath(opts.outpath or config['art_filename'].get())
for item in lib.items(decargs(args)):
if self.extract(outpath, item):
if opts.outpath:
self.extract_first(normpath(opts.outpath),
lib.items(decargs(args)))
else:
filename = opts.filename or config['art_filename'].get()
if os.path.dirname(filename) != '':
self._log.error(u"Only specify a name rather than a path "
u"for -n")
return
for album in lib.albums(decargs(args)):
artpath = normpath(os.path.join(album.path, filename))
artpath = self.extract_first(artpath, album.items())
if artpath and opts.associate:
album.set_art(artpath)
album.store()
extract_cmd.func = extract_func
# Clear command.
@ -236,7 +254,6 @@ class EmbedCoverArtPlugin(BeetsPlugin):
return mf.art
# 'extractart' command.
def extract(self, outpath, item):
art = self.get_art(item)
@ -258,6 +275,12 @@ class EmbedCoverArtPlugin(BeetsPlugin):
f.write(art)
return outpath
def extract_first(self, outpath, items):
for item in items:
real_path = self.extract(outpath, item)
if real_path:
return real_path
# 'clearart' command.
def clear(self, lib, query):
id3v23 = config['id3v23'].get(bool)

View file

@ -24,6 +24,9 @@ Features:
* :doc:`plugins/mbsync`: A new ``-f/--format`` option controls the output
format when listing unrecognized items. The output is also now more helpful
by default. :bug:`1246`
* :doc:`/plugins/fetchart`: New option ``-n`` to extract the cover art of all
matched albums into its directory. It's also possible to automatically
associate them with the album when adding ``-a``. :bug:`1261`
* :doc:`/plugins/fetchart`: Names of extracted image art is taken from the
``art_filename`` configuration option. :bug:`1258`
* :doc:`/plugins/fetchart`: There's a new Wikipedia image source that uses

View file

@ -77,12 +77,19 @@ embedded album art:
use a specific image file from the filesystem; otherwise, each album embeds
its own currently associated album art.
* ``beet extractart [-o FILE] QUERY``: extracts the image from an item matching
the query and stores it in a file. You can specify the destination file using
the ``-o`` option, but leave off the extension: it will be chosen
automatically. The destination filename is specified using the
``art_filename`` configuration option. It defaults to ``cover`` if it's not
specified via ``-o`` nor the config.
* ``beet extractart [-a] [-n FILE] QUERY``: extracts the images for all albums
matching the query. The images are placed inside the album folder. You can
specify the destination file name using the ``-n`` option, but leave off the
extension: it will be chosen automatically. The destination filename is
specified using the ``art_filename`` configuration option. It defaults to
``cover`` if it's not specified via ``-o`` nor the config.
Using ``-a``, the extracted image files are automatically associated with the
corresponding album.
* ``beet extractart -o FILE QUERY``: extracts the image from an item matching
the query and stores it in a file. You have to specify the destination file
using the ``-o`` option, but leave off the extension: it will be chosen
automatically.
* ``beet clearart QUERY``: removes all embedded images from all items matching
the query. (Use with caution!)