diff --git a/bin/exif-fixdatetime b/bin/exif-fixdatetime index 909edcb..202d67b 100755 --- a/bin/exif-fixdatetime +++ b/bin/exif-fixdatetime @@ -6,6 +6,7 @@ export LOGFILE=./$(basename $0).move.log [ -z "${forcedate+x}" ] && forcedate=false [ -z "${setdate+x}" ] && setdate=true [ -z "${setoriginalfilename+x}" ] && setoriginalfilename=false +[ -z "${movecreatedate+x}" ] && movecreatedate=false @@ -29,7 +30,13 @@ help () { Defaults: # commands - move=$move [false|true|copy] false: file is not moved to destination; true: file is moved; copy: copy file to destination + move=$move [false|true|copy|rename|renameinplace|copyrename] + false: file is not moved to destination; + true: file is moved; copy: copy file to destination + copy: copy file to final destinateion + renameinplace: rename file to YYYYMMDD_HHmmss-c.ext in place (just rename file) + rename: move like true, but rename ist like renameinplace + copyrename: rename file in place and copy it to final destination with new name forcedate=$forcedate [fase|true] false: datetimeoriginal and createdate is only updated from filename, if not set; true: tags are always updated setdate=$setdate [false|true] false: do not set date-tags, only if you are sure, tags are ok, and you want move or copy files; setoriginalfilenamee=$setoriginalfilename [false|true|force] false: do not set originalfilename from filname (default); true: set it, if not set; force: set it, also if exists; @@ -46,7 +53,7 @@ help () { ${dest}/${mimedestvid}/${subdestvid}/%Y/%Y_%m" Supported Filet-extensions - *.jpg, *.jpeg, *.png, *.mp4 + *.jpg, *.jpeg, *.png, *.mp4, *.3gp, *.gif Examples: @@ -90,6 +97,13 @@ parsedatetime() { 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 + # signal-2020-08-09-171936.jpg + if [[ $filename =~ ^.*([0-9]{4})(\.|-)([0-9]{2})(\.|-)([0-9]{2})( |_|-|" at ")([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[8]#0}" "${BASH_REMATCH[9]#0}")" + fi + 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}")" @@ -119,6 +133,7 @@ parsedatetime() { fi fi + echo "$result" return 0 } @@ -137,6 +152,9 @@ run_fix () { image/jpeg) MIMEDEST="${mimedestpic}/${subdestpic}" ;; + image/gif) + MIMEDEST="${mimedestpic}/${subdestpic}" + ;; video/mp4|video/m4a|video/3gpp) MIMEDEST="${mimedestvid}/${subdestvid}" ;; @@ -148,11 +166,11 @@ run_fix () { case $setoriginalfilename in true) - loginfo -n "set original filename: " + loginfo "set original filename: " $setoriginalfilename && exiftool -overwrite_original "-originalfilename&1 |tee -a ${LOGFILE})" + if $movecreatedate ; then + loginfo "$(exiftool '-Directory&1 |tee -a ${LOGFILE})" + else + loginfo "$(exiftool '-Directory&1 |tee -a ${LOGFILE})" + fi ;; copy) echo copy to ${dest}/${MIMEDEST}/%Y/%Y_%m - loginfo "$(exiftool -o . '-Directory&1 |tee -a ${LOGFILE})" - logwarn "$(readlink -f "$file"): $(exiftool -filename -if '(not ($datetimeoriginal or $createdate))' "$file")" + if $movecreatedate ; then + loginfo "$(exiftool -o . '-Directory&1 |tee -a ${LOGFILE})" + logwarn "$(readlink -f "$file"): $(exiftool -filename -if '(not ($datetimeoriginal or $createdate))' "$file")" + else + loginfo "$(exiftool -o . '-Directory&1 |tee -a ${LOGFILE})" + logwarn "$(readlink -f "$file"): $(exiftool -filename -if '(not ($datetimeoriginal or $createdate))' "$file")" + fi + ;; + renameinplace) + echo rename inplace + if $movecreatedate ; then + loginfo "$(exiftool '-FileName&1 | tee -a ${LOGFILE})" + else + loginfo "$(exiftool '-FileName&1 | tee -a ${LOGFILE})" + fi + ;; + rename) + echo move to ${dest}/${MIMEDEST}/%Y/%Y_%m + if $movecreatedate ; then + loginfo "$(exiftool -v '-FileName&1 | tee -a ${LOGFILE})" + else + loginfo "$(exiftool -v '-FileName&1 | tee -a ${LOGFILE})" + fi + ;; + copyrename) + echo move to ${dest}/${MIMEDEST}/%Y/%Y_%m + if $movecreatedate ; then + loginfo "$(exiftool -o . '-FileName&1 | tee -a ${LOGFILE})" + else + loginfo "$(exiftool -o . '-FileName&1 | tee -a ${LOGFILE})" + fi ;; *) logwarn "value for move is neither »true« nor »copy«" @@ -210,9 +261,9 @@ if [ $# -gt 0 ]; then esac else - loginfo "Progress all *.jpg, *.jpeg, *.png and mp4, *.3gp files in pwd $(pwd)" - all=$(find ${maxdepth:+-maxdepth} ${maxdepth:+$maxdepth} -type f |grep -i ".jpg$\|.jpeg$\|.mp4$\|.png$\|.3gp$"|wc -l) - find ${maxdepth:+-maxdepth} ${maxdepth:+$maxdepth} -type f |grep -i ".jpg$\|.jpeg$\|.mp4$\|.png$\|.3gp$"|while read file; do + loginfo "Progress all *.jpg, *.jpeg, *.png and mp4, *.3gp, *.gif files in pwd $(pwd)" + all=$(find ${maxdepth:+-maxdepth} ${maxdepth:+$maxdepth} -type f |grep -i ".jpg$\|.jpeg$\|.mp4$\|.png$\|.3gp$\|.gif$"|wc -l) + find ${maxdepth:+-maxdepth} ${maxdepth:+$maxdepth} -type f |grep -i ".jpg$\|.jpeg$\|.mp4$\|.png$\|.3gp$\|.gif$"|while read file; do let "i=i+1" loginfo "$i/$all" run_fix "$file"