Skip to content

Commit

Permalink
fetchart complains if no imaging backend available
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tomjaspers committed May 18, 2015
1 parent 0377510 commit a82dee3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions beetsplug/fetchart.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,16 @@ def _is_valid_image_candidate(self, candidate):
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])

Expand Down Expand Up @@ -446,6 +455,7 @@ def art_for_album(self, album, paths, local_only=False):

if self.maxwidth and out:
out = ArtResizer.shared.resize(self.maxwidth, out)

return out

def batch_fetch_art(self, lib, albums, force):
Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions docs/plugins/fetchart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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::
Expand Down
8 changes: 8 additions & 0 deletions test/test_art.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@
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()
Expand Down Expand Up @@ -408,11 +412,15 @@ def _assertImageIsValidArt(self, image_file, should_exist):
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)
Expand Down

0 comments on commit a82dee3

Please sign in to comment.