bugfix : try to use different exif tag for datetime

This commit is contained in:
Antoine Van Elstraete 2019-05-17 19:01:46 +02:00 committed by Antoine Van Elstraete
parent e40f546137
commit bb90e192e9

22
exv.py
View File

@ -48,7 +48,9 @@ def extractor(input_files, start, end, recursive):
"Photo.PixelYDimension", "Photo.PixelYDimension",
"Image.ImageWidth", "Image.ImageWidth",
"Image.ImageLength", "Image.ImageLength",
"Photo.DateTimeOriginal" "Photo.DateTimeOriginal",
"Photo.DateTimeDigitized",
"Exif.Image.DateTime"
] ]
for item in input_files: for item in input_files:
if isdir(item): if isdir(item):
@ -72,9 +74,9 @@ def extractor(input_files, start, end, recursive):
extracted_data = extracted_data.stdout.read().decode() extracted_data = extracted_data.stdout.read().decode()
if extracted_data: if extracted_data:
extracted_data = extracted_data.splitlines()[0] extracted_data = extracted_data.splitlines()[0]
exif_dict.update({extracted.split(".")[1]: extracted_data}) exif_dict.update({extracted.split(".")[-1]: extracted_data})
else: else:
exif_dict.update({extracted.split(".")[1]: None}) exif_dict.update({extracted.split(".")[-1]: None})
if exif_dict['FocalLength']: if exif_dict['FocalLength']:
exif_dict['FocalLength'] = float( exif_dict['FocalLength'] = float(
exif_dict['FocalLength'].replace(" mm", "")) exif_dict['FocalLength'].replace(" mm", ""))
@ -94,8 +96,16 @@ def extractor(input_files, start, end, recursive):
else: else:
pixels = None pixels = None
if exif_dict['DateTimeOriginal']: if exif_dict['DateTimeOriginal']:
exif_dict['DateTimeOriginal'] = datetime.strptime( exif_dict['DateTime'] = datetime.strptime(
exif_dict['DateTimeOriginal'], "%Y:%m:%d %H:%M:%S") exif_dict['DateTimeOriginal'], "%Y:%m:%d %H:%M:%S")
elif exif_dict['DateTimeDigitized']:
exif_dict['DateTime'] = datetime.strptime(
exif_dict['DateTimeDigitized'], "%Y:%m:%d %H:%M:%S")
elif exif_dict['DateTime']:
exif_dict['DateTime'] = datetime.strptime(
exif_dict['DateTime'], "%Y:%m:%d %H:%M:%S")
else:
exif_dict['DateTime'] = None
if exif_dict['ExposureTime']: if exif_dict['ExposureTime']:
try: try:
exif_dict['ExposureTime'] = float( exif_dict['ExposureTime'] = float(
@ -114,7 +124,7 @@ def extractor(input_files, start, end, recursive):
cameras_list, lenses_list, focals_list, apertures_list, exposures_list = [], [], [], [], [] cameras_list, lenses_list, focals_list, apertures_list, exposures_list = [], [], [], [], []
isos_list, dimensions_list, cameras_lenses_list, dates_list = [], [], [], [] isos_list, dimensions_list, cameras_lenses_list, dates_list = [], [], [], []
for data in exif_dict_list: for data in exif_dict_list:
if start <= data['DateTimeOriginal'] <= end: if data['DateTime'] and start <= data['DateTime'] <= end:
cameras_list.append(data['Model']) cameras_list.append(data['Model'])
lenses_list.append(data['LensModel']) lenses_list.append(data['LensModel'])
focals_list.append(data['FocalLength']) focals_list.append(data['FocalLength'])
@ -125,7 +135,7 @@ def extractor(input_files, start, end, recursive):
if data['LensModel']: if data['LensModel']:
cameras_lenses_list.append( cameras_lenses_list.append(
"{} + {}".format(data['Model'], data['LensModel'])) "{} + {}".format(data['Model'], data['LensModel']))
dates_list.append(data['DateTimeOriginal'].strftime("%Y%m%d")) dates_list.append(data['DateTime'].strftime("%Y%m%d"))
for camera in list(set(cameras_list)): for camera in list(set(cameras_list)):
if camera: if camera:
cameras.update({camera: cameras_list.count(camera)}) cameras.update({camera: cameras_list.count(camera)})