diff options
| -rw-r--r-- | libmat2/images.py | 20 | ||||
| -rw-r--r-- | libmat2/parser_factory.py | 4 | ||||
| -rw-r--r-- | tests/data/dirty.heic | bin | 0 -> 1322449 bytes | |||
| -rw-r--r-- | tests/test_libmat2.py | 11 |
4 files changed, 35 insertions, 0 deletions
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): | |||
| 181 | line = re.sub(r"\s+", "", line, flags=re.UNICODE) | 181 | line = re.sub(r"\s+", "", line, flags=re.UNICODE) |
| 182 | fout.write(line) | 182 | fout.write(line) |
| 183 | return True | 183 | return True |
| 184 | |||
| 185 | class HEICParser(exiftool.ExiftoolParser): | ||
| 186 | mimetypes = {'image/heic'} | ||
| 187 | meta_allowlist = {'SourceFile', 'ExifToolVersion', 'FileName','Directory', | ||
| 188 | 'FileSize', 'FileModifyDate', 'FileAccessDate', | ||
| 189 | 'FileInodeChangeDate', 'FilePermissions', 'FileType', | ||
| 190 | 'FileTypeExtension', 'MIMEType', 'MajorBrand', 'MinorVersion', | ||
| 191 | 'CompatibleBrands','HandlerType', 'PrimaryItemReference', | ||
| 192 | 'HEVCConfigurationVersion', 'GeneralProfileSpace', | ||
| 193 | 'GeneralTierFlag', 'GeneralProfileIDC', | ||
| 194 | 'GenProfileCompatibilityFlags', 'ConstraintIndicatorFlags', | ||
| 195 | 'GeneralLevelIDC', 'MinSpatialSegmentationIDC', | ||
| 196 | 'ParallelismType','ChromaFormat', 'BitDepthLuma', 'BitDepthChroma', | ||
| 197 | 'NumTemporalLayers', 'TemporalIDNested', 'ImageWidth', | ||
| 198 | 'ImageHeight', 'ImageSpatialExtent', 'ImagePixelDepth', | ||
| 199 | 'AverageFrameRate', 'ConstantFrameRate', 'MediaDataSize', | ||
| 200 | 'MediaDataOffset','ImageSize', 'Megapixels'} | ||
| 201 | |||
| 202 | def remove_all(self) -> bool: | ||
| 203 | 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') | |||
| 11 | mimetypes.add_type('application/epub+zip', '.epub') | 11 | mimetypes.add_type('application/epub+zip', '.epub') |
| 12 | mimetypes.add_type('application/x-dtbncx+xml', '.ncx') # EPUB Navigation Control XML File | 12 | mimetypes.add_type('application/x-dtbncx+xml', '.ncx') # EPUB Navigation Control XML File |
| 13 | 13 | ||
| 14 | # This should be removed after we move to python3.10 | ||
| 15 | # https://github.com/python/cpython/commit/20a5b7e986377bdfd929d7e8c4e3db5847dfdb2d | ||
| 16 | mimetypes.add_type('image/heic', '.heic') | ||
| 17 | |||
| 14 | 18 | ||
| 15 | def __load_all_parsers(): | 19 | def __load_all_parsers(): |
| 16 | """ Loads every parser in a dynamic way """ | 20 | """ 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 --- /dev/null +++ b/tests/data/dirty.heic | |||
| Binary files 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): | |||
| 251 | meta = p.get_meta() | 251 | meta = p.get_meta() |
| 252 | self.assertEqual(meta['Name'], 'I am so') | 252 | self.assertEqual(meta['Name'], 'I am so') |
| 253 | 253 | ||
| 254 | def test_heic(self): | ||
| 255 | p = images.HEICParser('./tests/data/dirty.heic') | ||
| 256 | meta = p.get_meta() | ||
| 257 | self.assertEqual(meta['ProfileCopyright'], 'Public Domain') | ||
| 258 | self.assertEqual(meta['ProfileDescription'], 'GIMP built-in sRGB') | ||
| 259 | |||
| 254 | 260 | ||
| 255 | class TestRemovingThumbnails(unittest.TestCase): | 261 | class TestRemovingThumbnails(unittest.TestCase): |
| 256 | def test_odt(self): | 262 | def test_odt(self): |
| @@ -504,6 +510,11 @@ class TestCleaning(unittest.TestCase): | |||
| 504 | 'EncodingSettings': 'Lavf52.103.0', | 510 | 'EncodingSettings': 'Lavf52.103.0', |
| 505 | }, | 511 | }, |
| 506 | 'expected_meta': {}, | 512 | 'expected_meta': {}, |
| 513 | },{ | ||
| 514 | 'name': 'heic', | ||
| 515 | 'parser': images.HEICParser, | ||
| 516 | 'meta': {}, | ||
| 517 | 'expected_meta': {}, | ||
| 507 | } | 518 | } |
| 508 | ] | 519 | ] |
| 509 | 520 | ||
