From de7768deae68a0ea0932d01de77d30c172f79a9a Mon Sep 17 00:00:00 2001 From: Malte Ried Date: Sat, 24 Jan 2015 15:59:13 +0100 Subject: [PATCH] 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: