mirror of
https://github.com/beetbox/beets.git
synced 2026-01-18 06:05:06 +01:00
Test invalid image format for MP4
This commit is contained in:
parent
d2b627cc1c
commit
28bab0a9a3
2 changed files with 19 additions and 7 deletions
|
|
@ -251,15 +251,10 @@ def _sc_encode(gain, peak):
|
|||
|
||||
|
||||
def _image_mime_type(data):
|
||||
"""Return the MIME type (either image/png or image/jpeg) of the
|
||||
image data (a bytestring).
|
||||
"""Return the MIME type of the image data (a bytestring).
|
||||
"""
|
||||
kind = imghdr.what(None, h=data)
|
||||
if kind == 'png':
|
||||
return 'image/png'
|
||||
else:
|
||||
# Currently just fall back to JPEG.
|
||||
return 'image/jpeg'
|
||||
return 'image/{0}'.format(kind)
|
||||
|
||||
# StorageStyle classes describe strategies for accessing values in
|
||||
# Mutagen file objects.
|
||||
|
|
@ -504,6 +499,8 @@ class MP4ImageStorageStyle(MP4ListStorageStyle):
|
|||
kind = mutagen.mp4.MP4Cover.FORMAT_PNG
|
||||
elif image.mime_type == 'image/jpeg':
|
||||
kind = mutagen.mp4.MP4Cover.FORMAT_JPEG
|
||||
else:
|
||||
raise ValueError('The MP4 format only supports PNG and JPEG images')
|
||||
return mutagen.mp4.MP4Cover(image.data, kind)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -46,6 +46,14 @@ class ArtTestMixin(object):
|
|||
return self._jpg_data
|
||||
_jpg_data = None
|
||||
|
||||
@property
|
||||
def tiff_data(self):
|
||||
if not self._jpg_data:
|
||||
with open(os.path.join(_common.RSRC, 'image-2x3.tiff'), 'rb') as f:
|
||||
self._jpg_data = f.read()
|
||||
return self._jpg_data
|
||||
_jpg_data = None
|
||||
|
||||
def test_set_png_art(self):
|
||||
mediafile = self._mediafile_fixture('empty')
|
||||
mediafile.art = self.png_data
|
||||
|
|
@ -578,6 +586,13 @@ class MP4Test(ReadWriteTestBase, PartialTestMixin,
|
|||
'bitdepth': 16,
|
||||
'channels': 2,
|
||||
}
|
||||
|
||||
def test_add_tiff_image_fails(self):
|
||||
mediafile = self._mediafile_fixture('empty')
|
||||
with self.assertRaises(ValueError):
|
||||
mediafile.images = [Image(data=self.tiff_data)]
|
||||
|
||||
|
||||
class AlacTest(ReadWriteTestBase, GenreListTestMixin, unittest.TestCase):
|
||||
extension = 'alac.m4a'
|
||||
audio_properties = {
|
||||
|
|
|
|||
Loading…
Reference in a new issue