#!/bin/bash [ -z "${move+x}" ] && move=false [ -z "${overwrite+x}" ] && overwrite=false export FILELOGLEVEL=WARN export SCRIPT_LOG=~/logs/exif.log parsedatetime() { filename="$(basename "${@}")" # 2015-09-11_17:41:53-1.jpg 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 [ -z "${result}" ]; then 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 fi if [ -z "${result}" ]; then # 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 fi if [ -z "${result}" ]; then # eYe20130323123316.jpg if [[ $filename =~ ^(eYe)([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[2]#0}" "${BASH_REMATCH[3]#0}" "${BASH_REMATCH[4]#0}" "${BASH_REMATCH[5]#0}" "${BASH_REMATCH[6]#0}" "${BASH_REMATCH[7]#0}")" fi fi if [ -z "${result}" ]; then # ./2016-01-22/IMG_4225.jpg if [[ "$(dirname ${@})" =~ ^.*/([0-9]{4})(\.|-)([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}" "00" "00" "00")" fi fi echo "$result" return 0 } fix_datetime () { file="${@}" loginfo "file: $file " newDateTimeOriginal="$(parsedatetime "$file")" loginfo "newDateTimeOriginal: $newDateTimeOriginal" mime="$(file --mime-type "$file" | awk '{print $NF}')" if [ -n "$newDateTimeOriginal" ]; then case $mime in image/png) exiftool "-creationtime=$newDateTimeOriginal" -if '(not $creationtime)' "$file" exiftool "-DateTimeOriginal=$newDateTimeOriginal" -if '(not $datetimeoriginal)' "$file" exiftool '-createdate&1 |tee -a dest_exists)" ;; copy) echo copy loginfo "$(exiftool -o . '-Directory