From 187b96edc074361f5cb3d5a6df48b187dcbfdcee Mon Sep 17 00:00:00 2001 From: "nath@home" Date: Fri, 26 Jun 2015 12:28:01 +0200 Subject: [PATCH] implement fix-jpeg-detection: detect jpeg files using their magic bytes following the unix file implementation by adding a test function to the imghdr.tests list, as intended --- beets/mediafile.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/beets/mediafile.py b/beets/mediafile.py index acc9dbc46..f5f342113 100644 --- a/beets/mediafile.py +++ b/beets/mediafile.py @@ -270,6 +270,20 @@ def _sc_encode(gain, peak): # Cover art and other images. +def _wider_test_jpeg(h, f): + """Test for a jpeg file following the UNIX file implementation which + uses the magic bytes rather just than looking for the bytes b'JFIF' + or b'EXIF' at a fixed position. + """ + if h[:2] == b'\xff\xd8': + return 'jpeg' + +# Add this new test function to the list of functions used by imghdr to +# determine the mime type +imghdr.tests.append(_wider_test_jpeg) + + + def _image_mime_type(data): """Return the MIME type of the image data (a bytestring). """