diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2c98c26 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +Pipfile* \ No newline at end of file diff --git a/README.md b/README.md index e369ffe..822aa1e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # EXIF2txt -Write EXIF metadata to text file,. \ No newline at end of file +Write EXIF metadata to text file. \ No newline at end of file diff --git a/exif2txt.py b/exif2txt.py index f9bce7e..1c2ce1d 100644 --- a/exif2txt.py +++ b/exif2txt.py @@ -1,4 +1,8 @@ # Write EXIF metadata to text file for pelican.photos plugin. +# The original version of this was 100% hard coded script, this version takes arguments to allow you to do more with it as a single install. +# The original is here - https://gist.github.com/Jeffmackinnon/92c747b30a873129a28cddacfc61fbe1 + +import argparse # The library that will parse the arguments. #import os from os import listdir @@ -11,6 +15,33 @@ from PIL.ExifTags import TAGS from fraction import Fraction +# Parser +parser = argparse.ArguemntParser( prog='exif2txt', + usage='%(prog)s [options] path', + allow_abbrev=False, + description='Write EXIF metadata to text file.', + epilog='it\'s my first public CLI python script, please be kind.', + ) + +parser.add_argument('Path', + metavar='path', + type=str, + help='top level path for with the images' + ) +# +# Need to add the parser for what information we want to add for each +# + + +# Execute parse_args() +args = parser.parse_args() +input_path = args.Path + +# Test to make sure that the Path given is valid. +if not os.path.isdir(input_path): + print('The path specified does not exist') + sys.exit() + # The first two functions are borrowed from github user @jpstroop # https://gist.github.com/jpstroop/58a21d02370c8ba34dc8f0fdd4206d70 @@ -32,10 +63,18 @@ def get_exif(image_path): except AttributeError: return None +# This is from J0el - https://gist.github.com/Jeffmackinnon/92c747b30a873129a28cddacfc61fbe1?permalink_comment_id=4185193#gistcomment-4185193 + +def exposure(ExposureTime): + try: + return( str(Fraction('ExposureTime'))) + except: + return('None') + #Creates a text file with some exif meta data. def write_exif_file(directory): # Open the exif.txt file, create if it doesn't exist, in the current folder. - txt = open(directory+'/exif.txt', 'w') + txt = open(directory +'/exif.txt', 'w') for file in os.listdir(directory): @@ -48,7 +87,7 @@ def write_exif_file(directory): os.path.join(file) + ': ' + str(image.get('Model')) + ' with a ' + str(image.get('LensModel')) + - ' - ' + str(image.get('ExposureTime')) + 's, ' + # I want to change this to fractions, but it works for now. + ' - ' + str(image.get(exposure(ExposureTime))) + 's, ' + # I want to change this to fractions, but it works for now. 'f/' + str(image.get('FNumber')) + ' at ISO-' + str(image.get('ISOSpeedRatings')) + '\n' @@ -58,20 +97,8 @@ def write_exif_file(directory): txt.close() return None -# The directory of the source photos, the same as PHOTO_LIBRARY in pelicanconf.py -# I run this in a WSL instance, but pelican is run on the host windows machine, hence the sample directory -dir = '/mnt/c/Users/jeff/Pictures' - # This walks through the directories and for each it calls the write exif file function -for root, subdirectories, files in os.walk(dir): +for root, subdirectories, files in os.walk(input_path): for subdirectory in subdirectories: print(os.path.join(root, subdirectory)) - write_exif_file(os.path.join(root, subdirectory)) - -# This is from J0el - https://gist.github.com/Jeffmackinnon/92c747b30a873129a28cddacfc61fbe1?permalink_comment_id=4185193#gistcomment-4185193 - -def exposure(ExposureTime): - try: - return( str(Fraction('ExposureTime'))) - except: - return('None') \ No newline at end of file + write_exif_file(os.path.join(root, subdirectory)) \ No newline at end of file