summaryrefslogtreecommitdiff
path: root/libmat2/exiftool.py
diff options
context:
space:
mode:
authorjvoisin2018-10-23 16:14:21 +0200
committerjvoisin2018-10-23 16:22:11 +0200
commitf1a071d460507fd1bb1721deafd2a8d9f88f5b05 (patch)
treee17067895ef1fc9b91b00c0ba56d2e86975ceef1 /libmat2/exiftool.py
parent38df679a88a19db3a4a82fdb8e20a42c9a53d1a1 (diff)
Implement lightweight cleaning for png and tiff
Diffstat (limited to 'libmat2/exiftool.py')
-rw-r--r--libmat2/exiftool.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/libmat2/exiftool.py b/libmat2/exiftool.py
index 11dd36d..23d0d89 100644
--- a/libmat2/exiftool.py
+++ b/libmat2/exiftool.py
@@ -1,4 +1,5 @@
1import json 1import json
2import logging
2import os 3import os
3import subprocess 4import subprocess
4from typing import Dict, Union, Set 5from typing import Dict, Union, Set
@@ -23,6 +24,34 @@ class ExiftoolParser(abstract.AbstractParser):
23 meta.pop(key, None) 24 meta.pop(key, None)
24 return meta 25 return meta
25 26
27 def _lightweight_cleanup(self):
28 if os.path.exists(self.output_filename):
29 try:
30 # exiftool can't force output to existing files
31 os.remove(self.output_filename)
32 except OSError as e: # pragma: no cover
33 logging.error("The output file %s is already existing and \
34 can't be overwritten: %s.", self.filename, e)
35 return False
36
37 # Note: '-All=' must be followed by a known exiftool option.
38 # Also, '-CommonIFD0' is needed for .tiff files
39 cmd = [_get_exiftool_path(),
40 '-all=', # remove metadata
41 '-adobe=', # remove adobe-specific metadata
42 '-exif:all=', # remove all exif metadata
43 '-Time:All=', # remove all timestamps
44 '-quiet', # don't show useless logs
45 '-CommonIFD0=', # remove IFD0 metadata
46 '-o', self.output_filename,
47 self.filename]
48 try:
49 subprocess.check_call(cmd)
50 except subprocess.CalledProcessError as e: # pragma: no cover
51 logging.error("Something went wrong during the processing of %s: %s", self.filename, e)
52 return False
53 return True
54
26def _get_exiftool_path() -> str: # pragma: no cover 55def _get_exiftool_path() -> str: # pragma: no cover
27 exiftool_path = '/usr/bin/exiftool' 56 exiftool_path = '/usr/bin/exiftool'
28 if os.path.isfile(exiftool_path): 57 if os.path.isfile(exiftool_path):