Created
April 8, 2013 19:30
-
-
Save jremus/5339730 to your computer and use it in GitHub Desktop.
Fixes the missing EXIF metadata in the JPEGs from an iOS AutoStitch export.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from argparse import ArgumentParser, ArgumentTypeError | |
import os.path | |
import fnmatch | |
from plistlib import readPlist | |
import exiftool | |
def directory(value): | |
if not os.path.isdir(value) or not os.path.exists(value): | |
msg = "'%s' is not a valid directory" % value | |
raise ArgumentTypeError(msg) | |
return value | |
parser = ArgumentParser(description='Fix AutoStitch Image Metadata') | |
parser.add_argument('--directory', type=directory, default=os.curdir, help='the directory to process') | |
args = parser.parse_args() | |
print 'Processing directory', args.directory, '...' | |
with exiftool.ExifTool() as et: | |
for fn in fnmatch.filter(os.listdir(args.directory), 'SavedFileInfo_*.xml'): | |
path = os.path.join(args.directory, fn) | |
if not os.path.isfile(path): | |
continue | |
print 'Processing plist', fn, '...' | |
pl = readPlist(path) | |
filenames = pl['originalsFileNames'] + [pl['panoFileName']] | |
filenames = map(os.path.basename, filenames) | |
filenames = map(lambda fn: os.path.join(args.directory, fn), filenames) | |
tags = [ | |
'DateTimeOriginal=%s' % pl['date'].strftime('%Y:%m:%d %H:%M:%S'), | |
'GPSTimeStamp=%s' % pl['date'].strftime('%Y:%m:%d %H:%M:%S'), | |
'GPSLatitude=%r' % abs(pl['latitude']), | |
'GPSLatitudeRef=%s' % ('N' if pl['latitude'] >= 0 else 'S'), | |
'GPSLongitude=%r' % abs(pl['longitude']), | |
'GPSLongitudeRef=%s' % ('E' if pl['longitude'] >= 0 else 'W') | |
# 'GPSAltitude=0', | |
# 'GPSAltitudeRef=0', | |
] | |
params = ["-" + t for t in tags] | |
params.extend(filenames) | |
try: | |
result = et.execute_json(*params) | |
print result | |
except ValueError: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment