myshellconfig/bin/exif-fixdatetime

49 lines
1.8 KiB
Text
Raw Normal View History

2020-11-10 17:26:25 +01:00
#!/bin/bash
export FILELOGLEVEL=ERROR
parsedatetime() {
filename="$(basename "${@}")"
if [[ $filename =~ ^([0-9]{4})(\.|-)([0-9]{2})(\.|-)([0-9]{2})( |_)([0-9]{2})(\.|-)([0-9]{2})(\.|-)([0-9]{2}).*$ ]]; then
result="$(printf "%04d:%02d:%02d %02d:%02d:%02d" "${BASH_REMATCH[1]#0}" "${BASH_REMATCH[3]#0}" "${BASH_REMATCH[5]#0}" "${BASH_REMATCH[7]#0}" "${BASH_REMATCH[9]#0}" "${BASH_REMATCH[11]#0}")"
fi
if [[ $filename =~ ^([0-9]{4})([0-9]{2})([0-9]{2})(_)([0-9]{2})([0-9]{2})([0-9]{2}).*$ ]]; then
result="$(printf "%04d:%02d:%02d %02d:%02d:%02d" "${BASH_REMATCH[1]#0}" "${BASH_REMATCH[2]#0}" "${BASH_REMATCH[3]#0}" "${BASH_REMATCH[5]#0}" "${BASH_REMATCH[6]#0}" "${BASH_REMATCH[7]#0}")"
fi
# Whatsapp-Bilder
if [[ $filename =~ ^(IMG-)([0-9]{4})([0-9]{2})([0-9]{2})(-WA)([0-9]{2})([0-9]{2}).*$ ]]; then
result="$(printf "%04d:%02d:%02d %02d:%02d:%02d" "${BASH_REMATCH[2]#0}" "${BASH_REMATCH[3]#0}" "${BASH_REMATCH[4]#0}" "${BASH_REMATCH[6]#0}" "${BASH_REMATCH[7]#0}" "00")"
fi
echo "$result"
return 0
}
fix_datetime () {
file="${@}"
loginfo "file: $file "
newDateTimeOriginal="$(parsedatetime "$file")"
loginfo "newDateTimeOriginal: $newDateTimeOriginal"
2020-11-10 17:30:13 +01:00
if [ -n "$newDateTimeOriginal" ]; then
exiftool "-DateTimeOriginal=$newDateTimeOriginal" -if '(not $datetimeoriginal)' "$file"
exiftool '-createdate<datetimeoriginal' -if '(not $createdate and $datetimeoriginal)' "$file"
2020-11-10 17:26:25 +01:00
fi
2020-11-10 17:30:13 +01:00
loginfo "$(exiftool -filename -createdate -datetimeoriginal "$file")"
loginfo "----------------"
loginfo ""
2020-11-10 17:26:25 +01:00
}
if [ $# -gt 0 ]; then
loginfo "Progress only one file from cmdline ${@}"
fix_datetime ${@}
else
loginfo "Progress all *.jpg files in pwd $(pwd)"
ls *.jpg|while read i; do
fix_datetime "$i"
done
fi