/
extract_utils.py
63 lines (46 loc) · 1.53 KB
/
extract_utils.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
import sys
import os
s = os.path.abspath('.')+'/libs/pyexif'
sys.path.append(s)
import exif
keys = set(['DateTime', 'ExposureProgram', 'ShutterSpeedValue',
'FNumber', 'FocalLength', 'ISOSpeedRatings', 'ExposureProgram',
'Model', 'ExposureTime', 'Orientation', 'MeteringMode'])
attr = {x: {} for x in keys}
def get_all_files(path):
""" This method returns the absolute values for all files in
the path given (string)"""
files = os.listdir(path)
files = map(lambda x: os.path.join(path, x), files)
dirs = filter(lambda x: os.path.isdir(x), files)
files = filter(lambda x: x.endswith(('jpg', 'JPG', 'CR2')), files)
for d in dirs:
files += get_all_files(d)
return files
def exif_map(files):
for i, f in enumerate(files):
print i, '/', len(files), f[f.index('.')+1:]
try:
info = exif.parse(f)
except:
print 'exception'
if 'Model' in info and info['Model'] != 'Canon EOS REBEL T3i':
continue
for k in set(info.keys()) & keys:
if k == 'DateTime': # cluster by day
value = info[k][0:10]
else:
value = info[k]
if value not in attr[k]:
attr[k][value] = 1
else:
attr[k][value] += 1
print(sys.argv)
photo_directory = sys.argv[1]
files = get_all_files(photo_directory)
print 'files ', len(files)
exif_map(files)
for k in attr:
print k
for kk in attr[k]:
print '\t', kk, '=>', attr[k][kk]