MCPcopy
hub / github.com/photonixapp/photonix / PhotoMetadata

Class PhotoMetadata

photonix/photos/utils/metadata.py:11–35  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9
10
11class PhotoMetadata(object):
12 def __init__(self, path):
13 self.data = {}
14 try:
15 # exiftool produces data such as MIME Type for non-photos too
16 result = Popen(['exiftool', path], stdout=PIPE, stdin=PIPE, stderr=PIPE).communicate()[0].decode('utf-8', 'ignore')
17 except UnicodeDecodeError:
18 result = ''
19 for line in str(result).split('\n'):
20 if line:
21 try:
22 k, v = line.split(':', 1)
23 self.data[k.strip()] = v.strip()
24 except ValueError:
25 pass
26
27 # Some file MIME Types can not be identified by exiftool so we fall back to Python's mimetypes library so the get_mimetype() funciton below is universal
28 if not self.data.get('MIME Type'):
29 self.data['MIME Type'] = mimetypes.guess_type(path)[0]
30
31 def get(self, attribute, default=None):
32 return self.data.get(attribute, default)
33
34 def get_all(self):
35 return self.data
36
37
38def parse_datetime(date_str):

Callers 11

record_photoFunction · 0.90
get_thumbnailFunction · 0.90
predictMethod · 0.90
predictMethod · 0.90
predictMethod · 0.90
predictMethod · 0.90
test_metadataFunction · 0.90
get_datetimeFunction · 0.85
get_dimensionsFunction · 0.85
get_mimetypeFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_metadataFunction · 0.72