diff --git a/libmat2/images.py b/libmat2/images.py index 3da2673..9c24998 100644 --- a/libmat2/images.py +++ b/libmat2/images.py @@ -181,3 +181,23 @@ class PPMParser(abstract.AbstractParser): line = re.sub(r"\s+", "", line, flags=re.UNICODE) fout.write(line) return True + +class HEICParser(exiftool.ExiftoolParser): + mimetypes = {'image/heic'} + meta_allowlist = {'SourceFile', 'ExifToolVersion', 'FileName','Directory', + 'FileSize', 'FileModifyDate', 'FileAccessDate', + 'FileInodeChangeDate', 'FilePermissions', 'FileType', + 'FileTypeExtension', 'MIMEType', 'MajorBrand', 'MinorVersion', + 'CompatibleBrands','HandlerType', 'PrimaryItemReference', + 'HEVCConfigurationVersion', 'GeneralProfileSpace', + 'GeneralTierFlag', 'GeneralProfileIDC', + 'GenProfileCompatibilityFlags', 'ConstraintIndicatorFlags', + 'GeneralLevelIDC', 'MinSpatialSegmentationIDC', + 'ParallelismType','ChromaFormat', 'BitDepthLuma', 'BitDepthChroma', + 'NumTemporalLayers', 'TemporalIDNested', 'ImageWidth', + 'ImageHeight', 'ImageSpatialExtent', 'ImagePixelDepth', + 'AverageFrameRate', 'ConstantFrameRate', 'MediaDataSize', + 'MediaDataOffset','ImageSize', 'Megapixels'} + + def remove_all(self) -> bool: + return self._lightweight_cleanup() diff --git a/libmat2/parser_factory.py b/libmat2/parser_factory.py index 9965432..a539d12 100644 --- a/libmat2/parser_factory.py +++ b/libmat2/parser_factory.py @@ -11,6 +11,10 @@ T = TypeVar('T', bound='abstract.AbstractParser') mimetypes.add_type('application/epub+zip', '.epub') mimetypes.add_type('application/x-dtbncx+xml', '.ncx') # EPUB Navigation Control XML File +# This should be removed after we move to python3.10 +# https://github.com/python/cpython/commit/20a5b7e986377bdfd929d7e8c4e3db5847dfdb2d +mimetypes.add_type('image/heic', '.heic') + def __load_all_parsers(): """ Loads every parser in a dynamic way """ diff --git a/tests/data/dirty.heic b/tests/data/dirty.heic new file mode 100644 index 0000000..0dc531d Binary files /dev/null and b/tests/data/dirty.heic differ diff --git a/tests/test_libmat2.py b/tests/test_libmat2.py index 9e56969..b32005f 100644 --- a/tests/test_libmat2.py +++ b/tests/test_libmat2.py @@ -251,6 +251,12 @@ class TestGetMeta(unittest.TestCase): meta = p.get_meta() self.assertEqual(meta['Name'], 'I am so') + def test_heic(self): + p = images.HEICParser('./tests/data/dirty.heic') + meta = p.get_meta() + self.assertEqual(meta['ProfileCopyright'], 'Public Domain') + self.assertEqual(meta['ProfileDescription'], 'GIMP built-in sRGB') + class TestRemovingThumbnails(unittest.TestCase): def test_odt(self): @@ -504,6 +510,11 @@ class TestCleaning(unittest.TestCase): 'EncodingSettings': 'Lavf52.103.0', }, 'expected_meta': {}, + },{ + 'name': 'heic', + 'parser': images.HEICParser, + 'meta': {}, + 'expected_meta': {}, } ]