From 0ed98515adc8b83add36e1d847b5848831cb68a4 Mon Sep 17 00:00:00 2001 From: kooimens Date: Fri, 30 Oct 2015 17:04:11 +0100 Subject: [PATCH 1/3] Embedart: remove_art_file on import Should fix #1662. I think the fix is easy. Don't know if it's clean though. Did some tests (+/- 10 albums), all successful. This is the first time I'm using python so please let me know what I should improve:) --- beetsplug/embedart.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/beetsplug/embedart.py b/beetsplug/embedart.py index 10b30af0f..9fb575429 100644 --- a/beetsplug/embedart.py +++ b/beetsplug/embedart.py @@ -141,3 +141,10 @@ class EmbedCoverArtPlugin(BeetsPlugin): art.embed_album(self._log, album, max_width, True, self.config['compare_threshold'].get(int), self.config['ifempty'].get(bool)) + if self.config['remove_art_file'] and album.artpath is not None: + if os.path.isfile(album.artpath): + self._log.debug(u'Removing album art file ' + u'for {0}', album) + os.remove(album.artpath) + album.artpath = None + album.store() From 0257b1077f682715f2b6785e9eebdfa0e1d1e312 Mon Sep 17 00:00:00 2001 From: kooimens Date: Fri, 30 Oct 2015 17:49:57 +0100 Subject: [PATCH 2/3] Simplify some code --- beetsplug/embedart.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/beetsplug/embedart.py b/beetsplug/embedart.py index 9fb575429..9afcf9cf4 100644 --- a/beetsplug/embedart.py +++ b/beetsplug/embedart.py @@ -80,7 +80,7 @@ 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 remove_art_file and album.artpath: if os.path.isfile(album.artpath): self._log.debug(u'Removing album art file ' u'for {0}', album) @@ -141,7 +141,7 @@ class EmbedCoverArtPlugin(BeetsPlugin): art.embed_album(self._log, album, max_width, True, self.config['compare_threshold'].get(int), self.config['ifempty'].get(bool)) - if self.config['remove_art_file'] and album.artpath is not None: + if self.config['remove_art_file'] and album.artpath: if os.path.isfile(album.artpath): self._log.debug(u'Removing album art file ' u'for {0}', album) From bcef3a71232ab66384f1ff532c334ef111eb9175 Mon Sep 17 00:00:00 2001 From: kooimens Date: Mon, 2 Nov 2015 23:56:38 +0100 Subject: [PATCH 3/3] Create function remove_artfile Damn it, that was really hard for me:D. First time seriously using python. Please review it carefuly. --- beetsplug/embedart.py | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/beetsplug/embedart.py b/beetsplug/embedart.py index 9afcf9cf4..df7f95d1d 100644 --- a/beetsplug/embedart.py +++ b/beetsplug/embedart.py @@ -79,14 +79,7 @@ class EmbedCoverArtPlugin(BeetsPlugin): for album in lib.albums(decargs(args)): art.embed_album(self._log, album, maxwidth, False, compare_threshold, ifempty) - - if remove_art_file and album.artpath: - if os.path.isfile(album.artpath): - self._log.debug(u'Removing album art file ' - u'for {0}', album) - os.remove(album.artpath) - album.artpath = None - album.store() + self.remove_artfile(album) embed_cmd.func = embed_func @@ -141,10 +134,12 @@ class EmbedCoverArtPlugin(BeetsPlugin): art.embed_album(self._log, album, max_width, True, self.config['compare_threshold'].get(int), self.config['ifempty'].get(bool)) - if self.config['remove_art_file'] and album.artpath: - if os.path.isfile(album.artpath): - self._log.debug(u'Removing album art file ' - u'for {0}', album) - os.remove(album.artpath) - album.artpath = None - album.store() + self.remove_artfile(album) + def remove_artfile(self, album) + if self.config['remove_art_file'] and album.artpath: + if os.path.isfile(album.artpath): + self._log.debug(u'Removing album art file ' + u'for {0}', album) + os.remove(album.artpath) + album.artpath = None + album.store()