From 29c6f9c342bb77a0d50157b973f3c3464f6a702f Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Wed, 31 Oct 2012 17:52:21 -0700 Subject: [PATCH] changelog and light style fixes for #64 --- beets/util/artresizer.py | 20 ++++++++++---------- docs/changelog.rst | 3 +++ docs/plugins/embedart.rst | 13 ++++++++----- docs/plugins/fetchart.rst | 24 +++++++++++++++++------- 4 files changed, 38 insertions(+), 22 deletions(-) diff --git a/beets/util/artresizer.py b/beets/util/artresizer.py index b2c2c7fca..2d7d96ba3 100644 --- a/beets/util/artresizer.py +++ b/beets/util/artresizer.py @@ -12,6 +12,9 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Abstraction layer to resize images using PIL, ImageMagick, or a +public resizing proxy if neither is available. +""" import urllib import subprocess import os @@ -20,8 +23,6 @@ import shutil from tempfile import NamedTemporaryFile import logging -"""Abstraction layer to resize an image without requiring additional dependency -""" # Resizing methods PIL = 1 IMAGEMAGICK = 2 @@ -29,10 +30,12 @@ WEBPROXY = 3 log = logging.getLogger('beets') + class ArtResizerError(Exception): - """Raised when an error occurs during image resizing + """Raised when an error occurs during image resizing. """ + def call(args): """Execute the command indicated by `args` (a list of strings) and return the command's output. The stderr stream is ignored. If the @@ -106,7 +109,8 @@ class ImageMagickResizer(object): class ArtResizer(object): - + """A singleton class that performs image resizes. + """ convert_path = None def __init__(self, detect=True): @@ -122,7 +126,6 @@ class ArtResizer(object): self.__class__ = ImageMagickResizer log.debug("ArtResizer method is %s" % self.__class__) - def set_method(self): """Set the most appropriate resize method. Use PIL if present, else check if ImageMagick is installed. @@ -148,7 +151,6 @@ class ArtResizer(object): return WEBPROXY - def resize(self, maxwidth, url, path_out=None): """Resize using web proxy. Return the output path of resized image. """ @@ -165,8 +167,6 @@ class ArtResizer(object): shutil.copy(fn, path_out) return path_out -# module-as-singleton instanciation + +# Singleton instantiation. inst = ArtResizer() - - - diff --git a/docs/changelog.rst b/docs/changelog.rst index 6f21b72c2..48de872b3 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -20,6 +20,9 @@ Changelog * :doc:`/plugins/replaygain`: This plugin has been completely overhauled to use the `mp3gain`_ or `aacgain`_ command-line tools instead of the failure-prone Gstreamer ReplayGain implementation. Thanks to Fabrice Laporte. +* :doc:`/plugins/fetchart` and :doc:`/plugins/embedart`: Both plugins can now + resize album art to avoid excessively large images. Thanks to + Fabrice Laporte. * :doc:`/plugins/scrub`: Scrubbing now removes *all* types of tags from a file rather than just one. For example, if your FLAC file has both ordinary FLAC tags and ID3 tags, the ID3 tags are now also removed. diff --git a/docs/plugins/embedart.rst b/docs/plugins/embedart.rst index 7246d2cdb..cf2639347 100644 --- a/docs/plugins/embedart.rst +++ b/docs/plugins/embedart.rst @@ -46,8 +46,11 @@ To do so, add this to your ``~/.beetsconfig``:: [embedart] autoembed: no -A maximum image width can be defined to downscale images before embedding them -(source image on filesystem is not altered). The resize operation reduces image width to -``maxwidth`` pixels and height is recomputed so that aspect ratio is preserved. -The [PIL](http://www.pythonware.com/products/pil/) or [ImageMagick](www.imagemagick.org/) is required -to use the ``maxwidth`` config option. \ No newline at end of file +A maximum image width can be configured as ``maxwidth`` to downscale images +before embedding them (the original image file is not altered). The resize +operation reduces image width to ``maxwidth`` pixels. The height is recomputed +so that the aspect ratio is preserved. `PIL`_ or `ImageMagick`_ is required to +use the ``maxwidth`` config option. + +.. _PIL: http://www.pythonware.com/products/pil/ +.. _ImageMagick: http://www.imagemagick.org/ diff --git a/docs/plugins/fetchart.rst b/docs/plugins/fetchart.rst index 73dd2ba25..359aa4dbe 100644 --- a/docs/plugins/fetchart.rst +++ b/docs/plugins/fetchart.rst @@ -16,12 +16,6 @@ By default, beets stores album art image files alongside the music files for an album in a file called ``cover.jpg``. To customize the name of this file, use the :ref:`art-filename` config option. -A maximum image width can be defined to downscale fetched images if they are too -big. The resize operation reduces image width to ``maxwidth`` pixels and -height is recomputed so that aspect ratio is preserved. -When using ``maxwidth`` config option, please consider installing -[ImageMagick](www.imagemagick.org/) first for optimal performance. - To disable automatic art downloading, just put this in your configuration file:: @@ -41,6 +35,22 @@ already have it; the ``-f`` or ``--force`` switch makes it search for art regardless. If you specify a query, only matching albums will be processed; otherwise, the command processes every album in your library. +Image Resizing +-------------- + +A maximum image width can be configured as ``maxwidth`` to downscale fetched +images if they are too big. The resize operation reduces image width to +``maxwidth`` pixels. The height is recomputed so that the aspect ratio is +preserved. + +Beets can resize images using `PIL`_, `ImageMagick`_, or a server-side resizing +proxy. If either PIL or ImageMagick is installed, beets will use those; +otherwise, it falls back to the resizing proxy. Since server-side resizing can +be slow, consider installing one of the two backends for better performance. + +.. _PIL: http://www.pythonware.com/products/pil/ +.. _ImageMagick: http://www.imagemagick.org/ + Album Art Sources ----------------- @@ -61,4 +71,4 @@ Embedding Album Art This plugin fetches album art but does not embed images into files' tags. To do that, use the :doc:`/plugins/embedart`. (You'll want to have both plugins -enabled.) \ No newline at end of file +enabled.)