From 1ee04fdaab75b2669d0c9eb4a31f2300495cb26f Mon Sep 17 00:00:00 2001 From: jvoisin <julien.voisin@dustri.org> Date: Sun, 15 Dec 2019 15:34:30 +0100 Subject: [PATCH] Improve exiftool-based parsers reliability --- libmat2/exiftool.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/libmat2/exiftool.py b/libmat2/exiftool.py index 89081e2..95c6825 100644 --- a/libmat2/exiftool.py +++ b/libmat2/exiftool.py @@ -20,13 +20,18 @@ class ExiftoolParser(abstract.AbstractParser): meta_allowlist = set() # type: Set[str] def get_meta(self) -> Dict[str, Union[str, dict]]: - if self.sandbox: - out = bubblewrap.run([_get_exiftool_path(), '-json', self.filename], - input_filename=self.filename, - check=True, stdout=subprocess.PIPE).stdout - else: - out = subprocess.run([_get_exiftool_path(), '-json', self.filename], - check=True, stdout=subprocess.PIPE).stdout + try: + if self.sandbox: + out = bubblewrap.run([_get_exiftool_path(), '-json', + self.filename], + input_filename=self.filename, + check=True, stdout=subprocess.PIPE).stdout + else: + out = subprocess.run([_get_exiftool_path(), '-json', + self.filename], check=True, + stdout=subprocess.PIPE).stdout + except subprocess.CalledProcessError: + raise ValueError meta = json.loads(out.decode('utf-8'))[0] for key in self.meta_allowlist: meta.pop(key, None) -- GitLab