diff --git a/picard/coverart/image.py b/picard/coverart/image.py index 6b246796bb..c8b8a344ae 100644 --- a/picard/coverart/image.py +++ b/picard/coverart/image.py @@ -170,13 +170,17 @@ def __init__(self, url=None, types=None, comment='', data=None, support_types=No self.can_be_saved_to_tags = True self.can_be_saved_to_disk = True self.can_be_saved_to_metadata = True - self.id3_type = id3_type if support_types is not None: self.support_types = support_types if support_multi_types is not None: self.support_multi_types = support_multi_types if data is not None: self.set_data(data) + try: + self.id3_type = id3_type + except ValueError: + log.warning("Invalid ID3 image type %r in %r", type, self) + self.id3_type = Id3ImageType.OTHER @property def source(self): diff --git a/test/test_coverart_image.py b/test/test_coverart_image.py index 5ea0fd2108..10f81ea9c4 100644 --- a/test/test_coverart_image.py +++ b/test/test_coverart_image.py @@ -148,6 +148,10 @@ def test_id3_type_value_error(self): with self.assertRaises(ValueError): image.id3_type = invalid_value + def test_init_invalid_id3_type(self): + image = CoverArtImage(id3_type=255) + self.assertEqual(image.id3_type, Id3ImageType.OTHER) + def test_compare_without_type(self): image1 = create_image(b'a', types=["front"]) image2 = create_image(b'a', types=["back"])