This commit is contained in:
Jeff MacKinnon 2022-10-27 10:54:11 -03:00
commit 50402c2d47

View file

@ -4,19 +4,19 @@
import argparse # The library that will parse the arguments. import argparse # The library that will parse the arguments.
#import os import os
from os import listdir from os import listdir
from os.path import isfile, join from os.path import isdir,isfile, join
#import PIL #import PIL
from PIL import Image from PIL import Image
from PIL.ExifTags import GPSTAGS from PIL.ExifTags import GPSTAGS
from PIL.ExifTags import TAGS from PIL.ExifTags import TAGS
from fraction import Fraction from fractions import Fraction
# Parser # Parser
parser = argparse.ArguemntParser( prog='exif2txt', parser = argparse.ArgumentParser( prog='exif2txt',
usage='%(prog)s [options] path', usage='%(prog)s [options] path',
allow_abbrev=False, allow_abbrev=False,
description='Write EXIF metadata to text file.', description='Write EXIF metadata to text file.',
@ -28,6 +28,8 @@ parser.add_argument('Path',
type=str, type=str,
help='top level path for with the images' help='top level path for with the images'
) )
# #
# Need to add the parser for what information we want to add for each # Need to add the parser for what information we want to add for each
# #
@ -64,12 +66,17 @@ def get_exif(image_path):
return None return None
# This is from J0el - https://gist.github.com/Jeffmackinnon/92c747b30a873129a28cddacfc61fbe1?permalink_comment_id=4185193#gistcomment-4185193 # This is from J0el - https://gist.github.com/Jeffmackinnon/92c747b30a873129a28cddacfc61fbe1?permalink_comment_id=4185193#gistcomment-4185193
# A couple of minor tweaks to make it work
def exposure(ExposureTime): def exposure(ExposureTime):
try: try:
return( str(Fraction('ExposureTime'))) time = float(ExposureTime)
if time > 1:
return(ExposureTime)
else:
return( str(Fraction(time).limit_denominator()))
except: except:
return('None') return(ExposureTime)
#Creates a text file with some exif meta data. #Creates a text file with some exif meta data.
def write_exif_file(directory): def write_exif_file(directory):
@ -83,11 +90,13 @@ def write_exif_file(directory):
if file.endswith(".jpg"): if file.endswith(".jpg"):
# Need to iterate through the files in the list and pass each to the # Need to iterate through the files in the list and pass each to the
image = get_exif(directory +'/'+os.path.join(file)) image = get_exif(directory +'/'+os.path.join(file))
txt.write( txt.write(
os.path.join(file) + ': ' + os.path.join(file) + ': ' +
str(image.get('Model')) + str(
image.get('Model')) +
' with a ' + str(image.get('LensModel')) + ' with a ' + str(image.get('LensModel')) +
' - ' + str(image.get(exposure(ExposureTime))) + 's, ' + # I want to change this to fractions, but it works for now. ' - ' + str(exposure(image.get('ExposureTime'))) + 's, ' + # I want to change this to fractions, but it works for now.
'f/' + str(image.get('FNumber')) + 'f/' + str(image.get('FNumber')) +
' at ISO-' + str(image.get('ISOSpeedRatings')) + ' at ISO-' + str(image.get('ISOSpeedRatings')) +
'\n' '\n'