mirror of
https://github.com/beetbox/beets.git
synced 2025-12-28 19:42:42 +01:00
detect 'edge' jpeg files without modifying imghdr.tests
This commit is contained in:
parent
b444ec496c
commit
106ea70fdb
1 changed files with 7 additions and 8 deletions
|
|
@ -270,24 +270,23 @@ def _sc_encode(gain, peak):
|
|||
|
||||
# Cover art and other images.
|
||||
|
||||
def _wider_test_jpeg(h, f):
|
||||
def _wider_test_jpeg(data):
|
||||
"""Test for a jpeg file following the UNIX file implementation which
|
||||
uses the magic bytes rather than just looking for the bytes b'JFIF'
|
||||
or b'EXIF' at a fixed position.
|
||||
"""
|
||||
if h[:2] == b'\xff\xd8':
|
||||
if data[:2] == b'\xff\xd8':
|
||||
return 'jpeg'
|
||||
|
||||
|
||||
def _image_mime_type(data):
|
||||
"""Return the MIME type of the image data (a bytestring).
|
||||
"""
|
||||
# imghdr provides access to the list of tests performed on an image to
|
||||
# determine its mimetype
|
||||
if not (_wider_test_jpeg in imghdr.tests):
|
||||
imghdr.tests.append(_wider_test_jpeg)
|
||||
|
||||
kind = imghdr.what(None, h=data)
|
||||
# This checks for a jpeg file with only the magic bytes (unrecognized by
|
||||
# imghdr.what). imghdr.what returns none for that type of file, so
|
||||
# _wider_test_jpeg is run in that case. It still returns None if it didn't
|
||||
# match such a jpeg file.
|
||||
kind = imghdr.what(None, h=data) or _wider_test_jpeg(data)
|
||||
if kind in ['gif', 'jpeg', 'png', 'tiff', 'bmp']:
|
||||
return 'image/{0}'.format(kind)
|
||||
elif kind == 'pgm':
|
||||
|
|
|
|||
Loading…
Reference in a new issue