From a82dee35cb63a6d278fb5037611e5efd3c36825c Mon Sep 17 00:00:00 2001 From: Tom Jaspers Date: Mon, 18 May 2015 19:44:40 +0200 Subject: [PATCH] fetchart complains if no imaging backend available The `enforce_ratio` and `minwidth` options depend on PIL or ImageMagick. Previously it silently fails. Now it will log a warning, and accept the image. Tests concerning these options are skipped when no imaging backend is available. Fix #1460 --- beetsplug/fetchart.py | 10 ++++++++++ docs/changelog.rst | 2 ++ docs/plugins/fetchart.rst | 6 ++++++ test/test_art.py | 8 ++++++++ 4 files changed, 26 insertions(+) diff --git a/beetsplug/fetchart.py b/beetsplug/fetchart.py index 2be0ed9c0..badac9d79 100644 --- a/beetsplug/fetchart.py +++ b/beetsplug/fetchart.py @@ -409,7 +409,16 @@ class FetchArtPlugin(plugins.BeetsPlugin): if not (self.enforce_ratio or self.minwidth): return True + # get_size returns None if no local imaging backend is available size = ArtResizer.shared.get_size(candidate) + + if not size: + self._log.warning(u'could not verify size of image: please see ' + u'documentation for dependencies. ' + u'The configuration options `minwidth` and ' + u'`enforce_ratio` may be violated.') + return True + return size and size[0] >= self.minwidth and \ (not self.enforce_ratio or size[0] == size[1]) @@ -446,6 +455,7 @@ class FetchArtPlugin(plugins.BeetsPlugin): if self.maxwidth and out: out = ArtResizer.shared.resize(self.maxwidth, out) + return out def batch_fetch_art(self, lib, albums, force): diff --git a/docs/changelog.rst b/docs/changelog.rst index 72eb157a0..eb80cddbc 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -11,6 +11,8 @@ New features: or alternatively any list of attributes that should be favored. * The :doc:`/plugins/metasync` plugin now lets you get metadata from iTunes. This plugin is still in an experimental phase. :bug:`1450` +* The :doc:`/plugins/fetchart` plugin will now complain for the `enforce_ratio` + and `min_width` options if no local imaging backend is available. :bug:`1460` Fixes: diff --git a/docs/plugins/fetchart.rst b/docs/plugins/fetchart.rst index 81f4be6aa..fef0d7f9e 100644 --- a/docs/plugins/fetchart.rst +++ b/docs/plugins/fetchart.rst @@ -54,6 +54,12 @@ file. The available options are: Default: ``coverart itunes albumart amazon google wikipedia``, i.e., all sources. +Note: ``minwidth`` and ``enforce_ratio`` options require either `ImageMagick`_ +or `PIL`_. + +.. _PIL: http://www.pythonware.com/products/pil/ +.. _ImageMagick: http://www.imagemagick.org/ + Here's an example that makes plugin select only images that contain *front* or *back* keywords in their filenames and prioritizes the iTunes source over others:: diff --git a/test/test_art.py b/test/test_art.py index 9825a4bc7..6fe62fc84 100644 --- a/test/test_art.py +++ b/test/test_art.py @@ -30,11 +30,15 @@ from beets import library from beets import importer from beets import config from beets import logging +from beets.util.artresizer import ArtResizer, WEBPROXY logger = logging.getLogger('beets.test_art') +ARTRESIZER_USES_FALLBACK_BACKEND = ArtResizer.shared.method[0] == WEBPROXY + + class UseThePlugin(_common.TestCase): def setUp(self): super(UseThePlugin, self).setUp() @@ -408,11 +412,15 @@ class ArtForAlbumTest(UseThePlugin): else: self.assertIsNone(local_artpath) + @unittest.skipIf(ARTRESIZER_USES_FALLBACK_BACKEND, + 'ArtResizer has no local imaging backend available') def test_respect_minwidth(self): self.plugin.minwidth = 300 self._assertImageIsValidArt(self.IMG_225x225, False) self._assertImageIsValidArt(self.IMG_348x348, True) + @unittest.skipIf(ARTRESIZER_USES_FALLBACK_BACKEND, + 'ArtResizer has no local imaging backend available') def test_respect_enforce_ratio_yes(self): self.plugin.enforce_ratio = True self._assertImageIsValidArt(self.IMG_500x490, False)