-
Notifications
You must be signed in to change notification settings - Fork 0
/
exif_processor.py
68 lines (47 loc) · 1.92 KB
/
exif_processor.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
__author__ = 'simon'
import json, os, urllib3
import exiftool
base_url = 'http://localhost:5000/'
next_url = 'http://localhost:5000/get'
progress_url = 'http://localhost:5000/update'
def __main__():
conn = urllib3.connection_from_url(next_url, maxsize=1, headers={'connection': 'keep-alive',})
while conn:
url = conn.request('GET', next_url)
if url:
data = json.loads(url.data)
if data is None:
break
process_tree(data['directory'])
def process_tree(head):
try:
for directory, dirnames, filenames in os.walk(head):
if dirnames:
for d in dirnames:
process_tree(os.path.join(head, d))
if filenames:
read_exif(filenames, directory)
except:
pass
def read_exif(files, source_folder):
with exiftool.ExifTool() as et:
#j = et.get_metadata('/'.join([source_folder, files[0]]))
f = ['/'.join([source_folder, j]) for j in files]
metadata = et.get_metadata_batch(f)
for d in metadata:
print(d["SourceFile"])
#[(k,d[k]) for k in d.keys() if str(d[k]).lower().find('g') >= 0]
conn = urllib3.connection_from_url(progress_url, maxsize=1,
headers={'Content-Type': 'application/json'})
myjson = {'folder': source_folder,
'file': d.get("SourceFile", None),
'focal_length': d.get(u'EXIF:FocalLengthIn35mmFormat', None),
'apeture': d.get(u'EXIF:FNumber', None),
'ISO': d.get(u"EXIF:ISO", None),
'shutter': d.get(u'EXIF:ExposureTime', None),
# 'raw_json': json.dumps(d)
}
# update status
conn.urlopen('POST', '/update', body=json.dumps(myjson), headers={'connection': 'keep-alive', 'Content-Type': 'application/json'})
if __name__ == '__main__':
__main__()