From 420b0724a041f633f5beb2f2b4bc39aa1196982b Mon Sep 17 00:00:00 2001 From: Jack Wilsdon Date: Sun, 6 Sep 2015 21:45:10 +0100 Subject: [PATCH 1/6] Add `remove_art_file` configuration property --- beetsplug/embedart.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/beetsplug/embedart.py b/beetsplug/embedart.py index 99be2180f..9a68fe820 100644 --- a/beetsplug/embedart.py +++ b/beetsplug/embedart.py @@ -37,6 +37,7 @@ class EmbedCoverArtPlugin(BeetsPlugin): 'auto': True, 'compare_threshold': 0, 'ifempty': False, + 'remove_art_file': False }) if self.config['maxwidth'].get(int) and not ArtResizer.shared.local: @@ -62,6 +63,7 @@ class EmbedCoverArtPlugin(BeetsPlugin): maxwidth = self.config['maxwidth'].get(int) compare_threshold = self.config['compare_threshold'].get(int) ifempty = self.config['ifempty'].get(bool) + remove_art_file = self.config['remove_art_file'].get(bool) def embed_func(lib, opts, args): if opts.file: @@ -78,6 +80,11 @@ class EmbedCoverArtPlugin(BeetsPlugin): art.embed_album(self._log, album, maxwidth, False, compare_threshold, ifempty) + if remove_art_file and album.artpath is not None: + if os.path.isfile(album.artpath): + self._log.debug(u'Removing album art file for {0}', album) + os.remove(album.artpath) + embed_cmd.func = embed_func # Extract command. From 9eb4fc530bd82a1e0c14344090bcd207a80ca0e3 Mon Sep 17 00:00:00 2001 From: Jack Wilsdon Date: Sun, 6 Sep 2015 21:53:34 +0100 Subject: [PATCH 2/6] Wrap line to ensure it is less than 80 characters --- beetsplug/embedart.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/beetsplug/embedart.py b/beetsplug/embedart.py index 9a68fe820..4ae081b2c 100644 --- a/beetsplug/embedart.py +++ b/beetsplug/embedart.py @@ -82,7 +82,8 @@ class EmbedCoverArtPlugin(BeetsPlugin): if remove_art_file and album.artpath is not None: if os.path.isfile(album.artpath): - self._log.debug(u'Removing album art file for {0}', album) + self._log.debug(u'Removing album art file ' + u'for {0}', album) os.remove(album.artpath) embed_cmd.func = embed_func From 110ab43db7ecb41fcda614dc27753c25021d34cc Mon Sep 17 00:00:00 2001 From: Jack Wilsdon Date: Sun, 6 Sep 2015 21:56:41 +0100 Subject: [PATCH 3/6] Add documentation for `remove_art_file` --- docs/plugins/embedart.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/plugins/embedart.rst b/docs/plugins/embedart.rst index f234bc057..f8ea0052c 100644 --- a/docs/plugins/embedart.rst +++ b/docs/plugins/embedart.rst @@ -58,6 +58,9 @@ file. The available options are: the aspect ratio is preserved. See also :ref:`image-resizing` for further caveats about image resizing. Default: 0 (disabled). +- **remove_art_file**: Automatically remove the album art file for the album + after it has been embedded. + Default: ``no``. Note: ``compare_threshold`` option requires `ImageMagick`_, and ``maxwidth`` requires either `ImageMagick`_ or `PIL`_. From ea247936c25c564abe300a66c3436a306de9b5bb Mon Sep 17 00:00:00 2001 From: Jack Wilsdon Date: Mon, 7 Sep 2015 01:21:47 +0100 Subject: [PATCH 4/6] Add purpose description to `remove_art_file` documentation --- docs/plugins/embedart.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/plugins/embedart.rst b/docs/plugins/embedart.rst index f8ea0052c..41cfaa87c 100644 --- a/docs/plugins/embedart.rst +++ b/docs/plugins/embedart.rst @@ -59,7 +59,10 @@ file. The available options are: caveats about image resizing. Default: 0 (disabled). - **remove_art_file**: Automatically remove the album art file for the album - after it has been embedded. + after it has been embedded. This option is best used alongside the + :doc:`FetchArt ` plugin to download art with the purpose of + directly embedding it into the file's metadata without an "intermediate" + album art file. Default: ``no``. Note: ``compare_threshold`` option requires `ImageMagick`_, and ``maxwidth`` From 38926caebe75c5d0aec1b1c2b6adeaceba87edf5 Mon Sep 17 00:00:00 2001 From: Jack Wilsdon Date: Mon, 7 Sep 2015 01:52:03 +0100 Subject: [PATCH 5/6] Reset album art to None when removed --- beetsplug/embedart.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/beetsplug/embedart.py b/beetsplug/embedart.py index 4ae081b2c..f965ecbeb 100644 --- a/beetsplug/embedart.py +++ b/beetsplug/embedart.py @@ -18,6 +18,7 @@ from __future__ import (division, absolute_import, print_function, import os.path +from beets import plugins from beets.plugins import BeetsPlugin from beets import ui from beets.ui import decargs @@ -85,6 +86,8 @@ class EmbedCoverArtPlugin(BeetsPlugin): self._log.debug(u'Removing album art file ' u'for {0}', album) os.remove(album.artpath) + album.artpath = None + album.store() embed_cmd.func = embed_func From 64e33b2d9a26258ef14e4409613c8baf0765bb85 Mon Sep 17 00:00:00 2001 From: Jack Wilsdon Date: Mon, 7 Sep 2015 01:55:44 +0100 Subject: [PATCH 6/6] Remove unused import --- beetsplug/embedart.py | 1 - 1 file changed, 1 deletion(-) diff --git a/beetsplug/embedart.py b/beetsplug/embedart.py index f965ecbeb..10b30af0f 100644 --- a/beetsplug/embedart.py +++ b/beetsplug/embedart.py @@ -18,7 +18,6 @@ from __future__ import (division, absolute_import, print_function, import os.path -from beets import plugins from beets.plugins import BeetsPlugin from beets import ui from beets.ui import decargs