Skip to content

Instantly share code, notes, and snippets.

@istais
Last active September 9, 2020 12:18
Show Gist options
  • Save istais/f35672d589fc4e4a4e3083458cd148d6 to your computer and use it in GitHub Desktop.
Save istais/f35672d589fc4e4a4e3083458cd148d6 to your computer and use it in GitHub Desktop.
#Find photos in "./GoogleDrive" folder with the format IMG_XXXYYZZ_KKLLMM.NNN.jpg and set their original taken date (if missing). This can be helpful if you want to import bulk photos to a photo manager (e.g. QNAP photostation)
#!/bin/bash
OIFS="$IFS"
IFS=$'\n'
for f in $(find ./GoogleDrive/* -name '*.jpg'); do
if [[ "$f" == *"__thumb"* ]]; then
true
else
if [[ "$f" == *"IMG_"* ]]; then
echo "$f"
check=$(exiftool -xmp:dateTimeOriginal "$f")
if [ "${check}" = "" ]; then
echo "does not have datetime"
cleaned=$( echo "$f" | awk -F'[/]' '{print $(NF)}')
createdname=$(echo "$cleaned" | sed -r 's/IMG_(.{4})(.{2})(.{2})_(.{2})(.{2})(.{2})(.*)/\1:\2:\3 \4:\5:\6/')
echo "${createdname}"
mypattern="^.{4}:.{2}:.{2} .{2}:.{2}:.{2}$"
if [[ ${createdname} =~ $mypattern ]]; then
echo "Matches!"
exiftool -xmp:dateTimeOriginal="$createdname" "$f"
fi
else
true;
fi
fi
fi
done
IFS="$OIFS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment