Created
October 2, 2018 04:55
-
-
Save lantrix/d3942b30be8735ef87faf48397bf048c to your computer and use it in GitHub Desktop.
Flickr Photo Download - Image processing for dates in OS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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