Cleaned up EXIF view

The last update made the assumption that EXIF metadata is in some way
consistent between camera models, images, manufacturers. This update
takes into account that nothing is certain whenever EXIF is involved.
This commit is contained in:
Joar Wandborg
2013-05-23 22:21:02 +02:00
parent 24ede04415
commit 14aa2eaa19
3 changed files with 53 additions and 57 deletions

View File

@@ -246,7 +246,8 @@ class MediaEntryMixin(GenerateSlugMixin):
exif_all = self.media_data.get("exif_all")
taken = None
exif_short = {}
if 'Image DateTimeOriginal' in exif_all:
# format date taken
takendate = datetime.datetime.strptime(
@@ -254,6 +255,8 @@ class MediaEntryMixin(GenerateSlugMixin):
'%Y:%m:%d %H:%M:%S').date()
taken = takendate.strftime('%B %d %Y')
exif_short.update({'Date Taken': taken})
aperture = None
if 'EXIF FNumber' in exif_all:
fnum = str(exif_all['EXIF FNumber']['printable']).split('/')
@@ -264,14 +267,25 @@ class MediaEntryMixin(GenerateSlugMixin):
elif fnum[0] != 'None':
aperture = "f/%s" % (fnum[0])
return {
"Camera" : exif_all['Image Model']['printable'],
"Exposure" : '%s sec' % exif_all['EXIF ExposureTime']['printable'],
"Aperture" : aperture,
"ISO" : exif_all['EXIF ISOSpeedRatings']['printable'],
"Focal Length" : '%s mm' % exif_all['EXIF FocalLength']['printable'],
"Date Taken" : taken,
}
if aperture:
exif_short.update({'Aperture': aperture})
short_keys = [
('Camera', 'Image Model', None),
('Exposure', 'EXIF ExposureTime', lambda x: '%s sec' % x),
('ISO Speed', 'EXIF ISOSpeedRatings', None),
('Focal Length', 'EXIF FocalLength', lambda x: '%s mm' % x)]
for label, key, fmt_func in short_keys:
try:
val = fmt_func(exif_all[key]['printable']) if fmt_func \
else exif_all[key]['printable']
exif_short.update({label: val})
except KeyError:
pass
return exif_short
class MediaCommentMixin(object):
@property