-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexif.py
33 lines (24 loc) · 921 Bytes
/
exif.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from exiftool import ExifTool, fsencode
class ExifError(Exception):
pass
class UnsupportedMIMETypeException(Exception):
pass
class Exif(ExifTool):
def execute_raw(self, *params):
params = map(fsencode, params)
return super().execute(*params).decode("utf-8")
def execute_json(self, *params):
json = super().execute_json(*params)
# Remove group names from keys
for d in json:
for k in list(d.keys()):
d[k.split(':')[-1]] = d.pop(k)
return json
def get_metadata(self, filename):
metadata = super().get_metadata(str(filename))
if 'Error' in metadata:
raise ExifError(metadata['Error'])
mime_type = metadata['MIMEType']
if not (mime_type.startswith('image/') or mime_type.startswith('video/')):
raise UnsupportedMIMETypeException(mime_type)
return metadata