mirror of
https://github.com/beetbox/beets.git
synced 2026-01-08 08:56:56 +01:00
Add support for different coverart mime types
This commit is contained in:
parent
28bab0a9a3
commit
9fe212feea
2 changed files with 31 additions and 1 deletions
|
|
@ -254,7 +254,19 @@ def _image_mime_type(data):
|
|||
"""Return the MIME type of the image data (a bytestring).
|
||||
"""
|
||||
kind = imghdr.what(None, h=data)
|
||||
return 'image/{0}'.format(kind)
|
||||
if kind in ['gif', 'jpeg', 'png', 'tiff', 'bmp']:
|
||||
return 'image/{0}'.format(kind)
|
||||
elif kind == 'pgm':
|
||||
return 'image/x-portable-graymap'
|
||||
elif kind == 'pbm':
|
||||
return 'image/x-portable-bitmap'
|
||||
elif kind == 'ppm':
|
||||
return 'image/x-portable-pixmap'
|
||||
elif kind == 'xbm':
|
||||
return 'image/x-xbitmap'
|
||||
else:
|
||||
return 'image/x-{0}'.format(kind)
|
||||
|
||||
|
||||
# StorageStyle classes describe strategies for accessing values in
|
||||
# Mutagen file objects.
|
||||
|
|
|
|||
|
|
@ -186,6 +186,24 @@ class ExtendedImageStructureTestMixin(ImageStructureTestMixin):
|
|||
self.assertEqual(image.desc, desc)
|
||||
self.assertEqual(image.type, type)
|
||||
|
||||
def test_add_tiff_image(self):
|
||||
mediafile = self._mediafile_fixture('image')
|
||||
self.assertEqual(len(mediafile.images), 2)
|
||||
|
||||
image = Image(data=self.tiff_data, desc='the composer',
|
||||
type=Image.TYPES.composer)
|
||||
mediafile.images += [image]
|
||||
mediafile.save()
|
||||
|
||||
mediafile = MediaFile(mediafile.path)
|
||||
self.assertEqual(len(mediafile.images), 3)
|
||||
|
||||
# WMA does not preserve the order, so we have to work around this
|
||||
image = filter(lambda i: i.mime_type == 'image/tiff',
|
||||
mediafile.images)[0]
|
||||
self.assertExtendedImageAttributes(image,
|
||||
desc='the composer', type=Image.TYPES.composer)
|
||||
|
||||
|
||||
# TODO include this in ReadWriteTestBase if implemented
|
||||
class LazySaveTestMixin(object):
|
||||
|
|
|
|||
Loading…
Reference in a new issue