Created
July 14, 2023 21:42
-
-
Save jchristgit/241203480b49afe2cff9c53612d2beca to your computer and use it in GitHub Desktop.
Copy DateTimeOriginal from EXIF metadata to file modification times and log output appropriately
This file contains 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 | |
set -euo pipefail | |
ARCHIVE="/your/gigantic/mess/of/pictures" | |
MEDIA="/path/to/your/cleaned-up/pictures/" | |
pushd $ARCHIVE >/dev/null | |
find . -type f -print0 | | |
while IFS= read -r -d $'\0' file; do | |
archivepath="$ARCHIVE/$file" | |
archivestat="$(stat --format="%Y" "$archivepath")" | |
mediapath="$MEDIA/$file" | |
if [ -e "$mediapath" ] && [[ ! "$mediapath" =~ .(BUP|IFO)$ ]]; then | |
gallerystat="$(stat --format="%Y" "$mediapath")" | |
archivedto="$(firejail --quiet --noprofile exiftool -ignoreMinorErrors -quiet -S -DateTimeOriginal "$mediapath" -d "%s" 2>/dev/null | awk '{ print $2 }')" | |
if [ "$archivedto" != "" ] \ | |
&& [[ "$archivedto" != "-1" ]] \ | |
&& date --date="@$archivedto" +%Y%m%d%H%M.%S |& cat > /dev/null \ | |
&& [[ "$archivedto" -lt "$archivestat" ]] \ | |
&& [[ "$archivedto" -lt "$gallerystat" ]]; then | |
in_touch_format="$(date --date="@$archivedto" +%Y%m%d%H%M.%S)" | |
touch -t "$in_touch_format" "$mediapath" | |
echo -n "^" | |
elif [[ "$archivestat" -lt "$gallerystat" ]]; then | |
touch --reference="$archivepath" -m "$mediapath" | |
echo -n "+" | |
elif [[ "$archivestat" -gt "$gallerystat" ]]; then | |
echo -n "!" | |
exit 1 | |
else | |
echo -n "." | |
fi | |
else | |
echo -n "x" | |
fi | |
done | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment