diff --git a/beetsplug/embedart.py b/beetsplug/embedart.py index 8e6dbab98..263980b3f 100644 --- a/beetsplug/embedart.py +++ b/beetsplug/embedart.py @@ -88,22 +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('-a', dest='albums', action='store_true', - help='extract the art of all matching ' - 'albums') + 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 = opts.outpath or config['art_filename'].get() - if opts.albums: - if opts.outpath and '/' in opts.outpath.replace('\\', '/'): - self._log.error(u"When using -a, only specify a filename " - u"instead of a full path for -o") + if opts.filename: + filename = opts.filename + if os.path.dirname(filename) != '': + self._log.error(u"Only specify a name rather a path for " + u"-n") return for album in lib.albums(decargs(args)): - artpath = normpath(os.path.join(album.path, outpath)) - self.extract_first(artpath, album.items()) + artpath = normpath(os.path.join(album.path, filename)) + artpath = self.extract_first(artpath, album.items()) + if artpath and opts.associate: + album.set_art(artpath) + else: - outpath = normpath(outpath) + outpath = normpath(opts.outpath + or config['art_filename'].get()) self.extract_first(outpath, lib.items(decargs(args))) extract_cmd.func = extract_func @@ -270,8 +278,9 @@ class EmbedCoverArtPlugin(BeetsPlugin): def extract_first(self, outpath, items): for item in items: - if self.extract(outpath, item): - return outpath + real_path = self.extract(outpath, item) + if real_path: + return real_path # 'clearart' command. def clear(self, lib, query): diff --git a/docs/changelog.rst b/docs/changelog.rst index a8dd71823..e61240165 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -26,8 +26,9 @@ Features: by default. :bug:`1246` * :doc:`/plugins/fetchart`: Names of extracted image art is taken from the ``art_filename`` configuration option. :bug:`1258` -* :doc:`/plugins/fetchart`: New option ``-a`` to extract the cover art of all - matched albums into its directory. :bug:`1261` +* :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`: There's a new Wikipedia image source that uses DBpedia to find albums. Thanks to Tom Jaspers. :bug:`1194` diff --git a/docs/plugins/embedart.rst b/docs/plugins/embedart.rst index 2c8748d14..e556ad90c 100644 --- a/docs/plugins/embedart.rst +++ b/docs/plugins/embedart.rst @@ -84,11 +84,11 @@ embedded album art: ``art_filename`` configuration option. It defaults to ``cover`` if it's not specified via ``-o`` nor the config. -* ``beet extractart -a [-o FILE] QUERY``: extracts the images for all albums +* ``beet extractart [-a] [-n FILE] QUERY``: extracts the images for all albums matching the query. The images are placed inside the album folder. The - destination filename is taken either from the ``-o`` option or the - ``art_filename`` configuration option. It defaults to ``cover`` if it's not - specified. + destination filename is taken either from the ``-n`` option. Using ``-a``, + the extracted image files are automatically associated with the corresponding + album. * ``beet clearart QUERY``: removes all embedded images from all items matching the query. (Use with caution!)