From b1bf7f3e681cec8f9aa01c651dff239f3e1fbfcc Mon Sep 17 00:00:00 2001 From: mried Date: Sat, 24 Jan 2015 11:15:36 +0100 Subject: [PATCH 1/2] Added an option to extract the art file of all matched albums. Closes #1261 --- beetsplug/embedart.py | 20 +++++++++++++++++--- docs/plugins/embedart.rst | 6 ++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/beetsplug/embedart.py b/beetsplug/embedart.py index 4609f9f50..d98fc1328 100644 --- a/beetsplug/embedart.py +++ b/beetsplug/embedart.py @@ -86,12 +86,26 @@ 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') 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.albums: + if opts.outpath and os.path.sep in normpath(opts.outpath): + self._log.error(u"When using -a, only specify a filename instead" + u" of a full path for -o") return + for album in lib.albums(decargs(args)): + outpath = normpath(os.path.join(album.path, opts.outpath + or config['art_filename'].get())) + for item in album.items(): + if self.extract(outpath, item): + return + else: + outpath = normpath(opts.outpath or config['art_filename'].get()) + for item in lib.items(decargs(args)): + if self.extract(outpath, item): + return extract_cmd.func = extract_func # Clear command. diff --git a/docs/plugins/embedart.rst b/docs/plugins/embedart.rst index 273046979..2c8748d14 100644 --- a/docs/plugins/embedart.rst +++ b/docs/plugins/embedart.rst @@ -84,5 +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 + 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. + * ``beet clearart QUERY``: removes all embedded images from all items matching the query. (Use with caution!) From de7768deae68a0ea0932d01de77d30c172f79a9a Mon Sep 17 00:00:00 2001 From: Malte Ried Date: Sat, 24 Jan 2015 15:59:13 +0100 Subject: [PATCH 2/2] Bugfixes and code rearrange for the extract art for albums feature. Closes #1261 --- beetsplug/embedart.py | 29 +++++++++++++++-------------- docs/changelog.rst | 2 ++ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/beetsplug/embedart.py b/beetsplug/embedart.py index d98fc1328..6b87b5a92 100644 --- a/beetsplug/embedart.py +++ b/beetsplug/embedart.py @@ -87,25 +87,22 @@ class EmbedCoverArtPlugin(BeetsPlugin): 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') + help='extract the art of all matching ' + 'albums') def extract_func(lib, opts, args): + outpath = opts.outpath or config['art_filename'].get() if opts.albums: - if opts.outpath and os.path.sep in normpath(opts.outpath): - self._log.error(u"When using -a, only specify a filename instead" - u" of a full path for -o") + 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") return for album in lib.albums(decargs(args)): - outpath = normpath(os.path.join(album.path, opts.outpath - or config['art_filename'].get())) - for item in album.items(): - if self.extract(outpath, item): - return + artpath = normpath(os.path.join(album.path, outpath)) + self.extract_first(artpath, album.items()) else: - outpath = normpath(opts.outpath or config['art_filename'].get()) - for item in lib.items(decargs(args)): - if self.extract(outpath, item): - return + outpath = normpath(outpath) + self.extract_first(outpath, lib.items(decargs(args))) extract_cmd.func = extract_func # Clear command. @@ -258,7 +255,6 @@ class EmbedCoverArtPlugin(BeetsPlugin): return mf.art # 'extractart' command. - def extract(self, outpath, item): if not item: self._log.error(u'No item matches query.') @@ -284,6 +280,11 @@ class EmbedCoverArtPlugin(BeetsPlugin): f.write(art) return outpath + def extract_first(self, outpath, items): + for item in items: + if self.extract(outpath, item): + return outpath + # 'clearart' command. def clear(self, lib, query): self._log.info(u'Clearing album art from items:') diff --git a/docs/changelog.rst b/docs/changelog.rst index 7ad300504..0774de98c 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -24,6 +24,8 @@ 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` Fixes: