embedart: fix error message when imagehdr fails

This commit is contained in:
Adrian Sampson 2013-09-12 10:45:02 -07:00
parent a785f66511
commit 19958f75ff
2 changed files with 21 additions and 7 deletions

View file

@ -34,8 +34,15 @@ def _embed(path, items, maxwidth=0):
data = open(syspath(path), 'rb').read()
kindstr = imghdr.what(None, data)
if kindstr not in ('jpeg', 'png'):
log.error('A file of type %s is not allowed as coverart.' % kindstr)
if kindstr is None:
log.error(u'Could not embed art of unkown type: {0}'.format(
displayable_path(path)
))
return
elif kindstr not in ('jpeg', 'png'):
log.error(u'Image type {0} is not allowed as cover art: {1}'.format(
kindstr, displayable_path(path)
))
return
# Add art to each file.
@ -110,8 +117,9 @@ def embed(lib, imagepath, query):
log.error('No album matches query.')
return
log.info('Embedding album art into %s - %s.' % \
(album.albumartist, album.album))
log.info(u'Embedding album art into {0.albumartist} - {0.album}.'.format(
album
))
_embed(imagepath, album.items(),
config['embedart']['maxwidth'].get(int))
@ -161,9 +169,8 @@ def extract(lib, outpath, query):
return
outpath += '.' + ext
log.info('Extracting album art from: %s - %s\n'
'To: %s' % \
(item.artist, item.title, outpath))
log.info(u'Extracting album art from: {0.artist} - {0.title}\n'
u'To: {1}'.format(item, displayable_path(outpath)))
with open(syspath(outpath), 'wb') as f:
f.write(art)

View file

@ -4,8 +4,15 @@ Changelog
1.3.1 (in development)
----------------------
New stuff:
* Add `Opus`_ audio support. Thanks to Rowan Lewis.
And some fixes:
* :doc:`/plugins/fetchart`: Better error message when the image file has an
unrecognized type.
.. _Ogg Opus: http://www.opus-codec.org/