summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjvoisin2022-05-15 18:57:27 +0200
committerjvoisin2022-05-15 18:57:27 +0200
commit704367f91eebe6158399f930f725334db96de134 (patch)
tree2a2f77e6e0b241b1120915df3608d961320072e7
parent263971370931b1c5b8c49ab287e6d30e40d974e2 (diff)
Add support for HEIC files
Thanks to Maxime Morin ( https://www.maijin.fr/ ) for the patch.
-rw-r--r--libmat2/images.py20
-rw-r--r--libmat2/parser_factory.py4
-rw-r--r--tests/data/dirty.heicbin0 -> 1322449 bytes
-rw-r--r--tests/test_libmat2.py11
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
185class 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')
11mimetypes.add_type('application/epub+zip', '.epub') 11mimetypes.add_type('application/epub+zip', '.epub')
12mimetypes.add_type('application/x-dtbncx+xml', '.ncx') # EPUB Navigation Control XML File 12mimetypes.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
16mimetypes.add_type('image/heic', '.heic')
17
14 18
15def __load_all_parsers(): 19def __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
255class TestRemovingThumbnails(unittest.TestCase): 261class 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