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: 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 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