mirror of
https://github.com/beetbox/beets.git
synced 2026-02-12 10:22:13 +01:00
log errors, don't crash, when calling convert
This commit is contained in:
parent
ea4e51b80e
commit
9294140388
2 changed files with 16 additions and 25 deletions
|
|
@ -32,24 +32,6 @@ PROXY_URL = 'http://images.weserv.nl/'
|
|||
log = logging.getLogger('beets')
|
||||
|
||||
|
||||
class ArtResizerError(Exception):
|
||||
"""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
|
||||
command exits abnormally, a ArtResizerError is raised.
|
||||
"""
|
||||
try:
|
||||
return util.command_output(args)
|
||||
except subprocess.CalledProcessError as e:
|
||||
raise ArtResizerError(
|
||||
"{0} exited with status {1}".format(args[0], e.returncode)
|
||||
)
|
||||
|
||||
|
||||
def resize_url(url, maxwidth):
|
||||
"""Return a proxied image URL that resizes the original image to
|
||||
maxwidth (preserving aspect ratio).
|
||||
|
|
@ -105,10 +87,16 @@ def im_resize(maxwidth, path_in, path_out=None):
|
|||
# than the corresponding width and/or height dimension(s). The >
|
||||
# "only shrink" flag is prefixed by ^ escape char for Windows
|
||||
# compatibility.
|
||||
call([
|
||||
'convert', util.syspath(path_in),
|
||||
'-resize', '{0}x^>'.format(maxwidth), path_out
|
||||
])
|
||||
try:
|
||||
util.command_output([
|
||||
'convert', util.syspath(path_in),
|
||||
'-resize', '{0}x^>'.format(maxwidth), path_out
|
||||
])
|
||||
except subprocess.CalledProcessError:
|
||||
log.warn(u'artresizer: IM convert failed for {0}'.format(
|
||||
util.displayable_path(path_in)
|
||||
))
|
||||
return path_in
|
||||
return path_out
|
||||
|
||||
|
||||
|
|
@ -189,11 +177,12 @@ class ArtResizer(object):
|
|||
|
||||
# Try invoking ImageMagick's "convert".
|
||||
try:
|
||||
out = subprocess.check_output(['convert', '--version']).lower()
|
||||
if 'imagemagick' in out:
|
||||
out = util.command_output(['convert', '--version'])
|
||||
if 'imagemagick' in out.lower():
|
||||
# system32/convert.exe may be interfering
|
||||
return IMAGEMAGICK
|
||||
except (subprocess.CalledProcessError, OSError):
|
||||
pass # system32/convert.exe may be interfering
|
||||
pass
|
||||
|
||||
# Fall back to Web proxy method.
|
||||
return WEBPROXY
|
||||
|
|
|
|||
|
|
@ -48,6 +48,8 @@ Other little fixes:
|
|||
* Fix a potential crash when using image resizing with the
|
||||
:doc:`/plugins/fetchart` or :doc:`/plugins/embedart` without ImageMagick
|
||||
installed.
|
||||
* Also, when invoking ``convert`` for image resizing fails, we now log an
|
||||
error instead of crashing.
|
||||
* :doc:`/plugins/fetchart`: The ``beet fetchart`` command can now associate
|
||||
local images with albums (unless ``--force`` is provided). Thanks to
|
||||
brilnius.
|
||||
|
|
|
|||
Loading…
Reference in a new issue