From b1bf7f3e681cec8f9aa01c651dff239f3e1fbfcc Mon Sep 17 00:00:00 2001 From: mried Date: Sat, 24 Jan 2015 11:15:36 +0100 Subject: [PATCH 1/7] 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/7] 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: From 6ac132edf75ad562cc95ec722ed790cbcfbb1c93 Mon Sep 17 00:00:00 2001 From: mried Date: Sat, 24 Jan 2015 11:15:36 +0100 Subject: [PATCH 3/7] 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 c43173263c2949f57a82d1c41267bf9b69da2352 Mon Sep 17 00:00:00 2001 From: Malte Ried Date: Sat, 24 Jan 2015 15:59:13 +0100 Subject: [PATCH 4/7] 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 96264ef6e..6c4295ae8 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: From 07cea164929ab9d8dd14b3ad4db92e8460007f39 Mon Sep 17 00:00:00 2001 From: Malte Ried Date: Tue, 27 Jan 2015 19:41:25 +0100 Subject: [PATCH 5/7] Changed the interface of extractart to make it easier to understand what it does. --- beetsplug/embedart.py | 35 ++++++++++++++++++++++------------- docs/changelog.rst | 5 +++-- docs/plugins/embedart.rst | 8 ++++---- 3 files changed, 29 insertions(+), 19 deletions(-) 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!) From 2c75d0567ffafe53564dc4b017a2dcaeb93530fc Mon Sep 17 00:00:00 2001 From: Malte Ried Date: Tue, 27 Jan 2015 19:59:49 +0100 Subject: [PATCH 6/7] Made the new functionality the default behaviour. --- beetsplug/embedart.py | 13 ++++++------- docs/changelog.rst | 4 ++-- docs/plugins/embedart.rst | 23 ++++++++++++----------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/beetsplug/embedart.py b/beetsplug/embedart.py index 263980b3f..10d3b945d 100644 --- a/beetsplug/embedart.py +++ b/beetsplug/embedart.py @@ -97,8 +97,11 @@ class EmbedCoverArtPlugin(BeetsPlugin): 'with the album') def extract_func(lib, opts, args): - if opts.filename: - filename = opts.filename + 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 a path for " u"-n") @@ -108,11 +111,7 @@ class EmbedCoverArtPlugin(BeetsPlugin): artpath = self.extract_first(artpath, album.items()) if artpath and opts.associate: album.set_art(artpath) - - else: - outpath = normpath(opts.outpath - or config['art_filename'].get()) - self.extract_first(outpath, lib.items(decargs(args))) + album.store() extract_cmd.func = extract_func # Clear command. diff --git a/docs/changelog.rst b/docs/changelog.rst index e61240165..7041bba13 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -24,11 +24,11 @@ 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`: Names of extracted image art is taken from the - ``art_filename`` configuration option. :bug:`1258` * :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 DBpedia to find albums. Thanks to Tom Jaspers. :bug:`1194` diff --git a/docs/plugins/embedart.rst b/docs/plugins/embedart.rst index e556ad90c..cf96c504f 100644 --- a/docs/plugins/embedart.rst +++ b/docs/plugins/embedart.rst @@ -77,18 +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. The - destination filename is taken either from the ``-n`` option. Using ``-a``, - the extracted image files are automatically associated with the corresponding - album. + 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!) From 67ecf32671965dfbc945774f80d61afb9f711a14 Mon Sep 17 00:00:00 2001 From: Malte Ried Date: Wed, 28 Jan 2015 15:46:16 +0100 Subject: [PATCH 7/7] Fixed typos. --- beetsplug/embedart.py | 4 ++-- docs/changelog.rst | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/beetsplug/embedart.py b/beetsplug/embedart.py index 10d3b945d..6e3783030 100644 --- a/beetsplug/embedart.py +++ b/beetsplug/embedart.py @@ -103,8 +103,8 @@ class EmbedCoverArtPlugin(BeetsPlugin): else: filename = opts.filename or config['art_filename'].get() if os.path.dirname(filename) != '': - self._log.error(u"Only specify a name rather a path for " - u"-n") + 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)) diff --git a/docs/changelog.rst b/docs/changelog.rst index efe2dc11f..30d26525c 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -26,7 +26,7 @@ Features: 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` + 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