From c90ca1096c0dde4ca88bfdb4d4963b7b7cddc8d6 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Mon, 23 Nov 2015 17:30:09 -0800 Subject: [PATCH 1/3] fetchart: Log reasons for rejecting art --- beetsplug/fetchart.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/beetsplug/fetchart.py b/beetsplug/fetchart.py index 333d29a89..1b2089b58 100644 --- a/beetsplug/fetchart.py +++ b/beetsplug/fetchart.py @@ -528,6 +528,7 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin): # get_size returns None if no local imaging backend is available size = ArtResizer.shared.get_size(candidate) + self._log.debug('image size: {}', size) if not size: self._log.warning(u'Could not get size of image (please see ' @@ -536,12 +537,25 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin): u'`enforce_ratio` may be violated.') return CANDIDATE_EXACT - if (not self.minwidth or size[0] >= self.minwidth) and ( - not self.enforce_ratio or size[0] == size[1]): - if not self.maxwidth or size[0] > self.maxwidth: - return CANDIDATE_DOWNSCALE - return CANDIDATE_EXACT - return CANDIDATE_BAD + # Check minimum size. + if self.minwidth and size[0] < self.minwidth: + self._log.debug('image too small ({} < {})', + size[0], self.minwidth) + return CANDIDATE_BAD + + # Check aspect ratio. + if self.enforce_ratio and size[0] != size[1]: + self._log.debug('image is not square ({} != {})', + size[0], size[1]) + return CANDIDATE_BAD + + # Check maximum size. + if self.maxwidth and size[0] > self.maxwidth: + self._log.debug('image needs resizing ({} > {})', + size[0], self.maxwidth) + return CANDIDATE_DOWNSCALE + + return CANDIDATE_EXACT def art_for_album(self, album, paths, local_only=False): """Given an Album object, returns a path to downloaded art for the From 4ccf81534e74096e507e622047c860219a3420dd Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Mon, 23 Nov 2015 22:47:52 -0800 Subject: [PATCH 2/3] Even more ImageMagick error logging (#1721) --- beets/util/__init__.py | 1 + beets/util/artresizer.py | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/beets/util/__init__.py b/beets/util/__init__.py index 5ea021bdd..e2d09c3ab 100644 --- a/beets/util/__init__.py +++ b/beets/util/__init__.py @@ -700,6 +700,7 @@ def command_output(cmd, shell=False): raise subprocess.CalledProcessError( returncode=proc.returncode, cmd=b' '.join(cmd), + output=stdout + stderr, ) return stdout diff --git a/beets/util/artresizer.py b/beets/util/artresizer.py index 775679568..6ef7770f8 100644 --- a/beets/util/artresizer.py +++ b/beets/util/artresizer.py @@ -123,10 +123,11 @@ def im_getsize(path_in): try: out = util.command_output(cmd) except subprocess.CalledProcessError as exc: - log.warn( - 'ImageMagick invocation failed when ' - 'getting size with command {}: {}', - cmd, exc + log.warn('ImageMagick size query failed') + log.debug( + '`convert` exited with (status {}) when ' + 'getting size with command {}:\n{}', + exc.returncode, cmd, exc.output.strip() ) return try: From 6958f83dd6e3807427aa4a08ae0133d14f1aa071 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Mon, 23 Nov 2015 22:55:51 -0800 Subject: [PATCH 3/3] Fix test for richer CalledProcessError --- test/test_util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_util.py b/test/test_util.py index 6dacb7f57..db68ed885 100644 --- a/test/test_util.py +++ b/test/test_util.py @@ -108,7 +108,7 @@ class UtilTest(unittest.TestCase): def test_command_output(self, mock_popen): def popen_fail(*args, **kwargs): m = Mock(returncode=1) - m.communicate.return_value = None, None + m.communicate.return_value = 'foo', 'bar' return m mock_popen.side_effect = popen_fail