Skip to content

Instantly share code, notes, and snippets.

@noah
Created January 4, 2017 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noah/693333188bae30f9e72048b47f331fa8 to your computer and use it in GitHub Desktop.
Save noah/693333188bae30f9e72048b47f331fa8 to your computer and use it in GitHub Desktop.
Count unique EXIF tags
def grouper(iterable, n, fillvalue=None):
args = [iter(iterable)] * n
return izip_longest(*args, fillvalue=fillvalue)
# read exif data and build a list of unique keys
media_files = []
for root, sub_folders, files in walk(app.config['MEDIA_ROOT']):
for f in files:
media_files.append(path.join(root, f))
chunksize=512
lm = len(media_files)
ng = lm / chunksize
exif_keys = {}
with ExifTool() as et:
print "Examining {} files ({} groups)".format(lm, ng)
for i, group in enumerate(grouper(media_files, chunksize)):
group = filter(None, group)
print "group #{}/{} group sz: {}".format(i, ng, len(group))
metadata = et.get_metadata_batch(group)
for entry in metadata:
for k,v in entry.items():
if k in exif_keys: exif_keys[k] += 1
else: exif_keys[k] = 1
print "Found {} keys".format(len(exif_keys))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment