Skip to content

Instantly share code, notes, and snippets.

@lantrix
Created October 2, 2018 04:55
Show Gist options
  • Save lantrix/d3942b30be8735ef87faf48397bf048c to your computer and use it in GitHub Desktop.
Save lantrix/d3942b30be8735ef87faf48397bf048c to your computer and use it in GitHub Desktop.
Flickr Photo Download - Image processing for dates in OS
#!/bin/bash
# When you download a zip of images from flickr, the files are named by flickr object IDs.
# Processing all files in a directory, this script will:
# - Change OS Modify date to match the EXIF OriginalDate of the image
# - Rename image to match EXIF OriginalDate in format:
# YYYY-MM-DD HH:mm:ss.ext
DIR="$1"
# failsafe - fall back to current directory
[ "$DIR" == "" ] && DIR="."
# save and change IFS
OLDIFS=$IFS
IFS=$'\n'
# read all file name into an array
fileArray=($(find $DIR -type f))
# restore it
IFS=$OLDIFS
# get length of an array
tLen=${#fileArray[@]}
echo "Number of files $tLen"
# use for loop read all filenames
for (( i=0; i<${tLen}; i++ ));
do
thisFile=${fileArray[$i]}
fileType=$(file -b -I ${fileArray[$i]})
if ! [[ $fileType == *"image"* ]]; then
echo "$thisFile is not an image ... skipping"
continue
fi
echo -n "$thisFile "
exiftool "${fileArray[$i]}" -ExifIFD:DateTimeOriginal
#change file OS modify date
exiftool -overwrite_original '-FileModifyDate<DateTimeOriginal' "${fileArray[$i]}"
#rename file
exiftool '-FileName<DateTimeOriginal' -d "%Y-%m-%d %H.%M.%S%%-c.%%e" "${fileArray[$i]}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment