add formats, add copy/move functions

This commit is contained in:
Jakobus Schürz 2020-11-27 19:38:57 +01:00
parent 0fc9fe4913
commit 4bfbace1a0

View file

@ -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<filename" -if '(not $originalfilename)' "$file"
;;
force)
loginfo -n "set original filename: "
loginfo "set original filename: "
$setoriginalfilename && exiftool -overwrite_original "-originalfilename<filename" "$file"
;;
*)
@ -164,14 +182,14 @@ run_fix () {
$setdate && [ -n "$newDateTimeOriginal" ] && exiftool -overwrite_original "-DateTimeOriginal=$newDateTimeOriginal" "$file"
loginfo -n "set createdate to datetimeoriginal: "
$setdate && exiftool -overwrite_original '-createdate<datetimeoriginal' -if '($datetimeoriginal)' "$file"
loginfo -n "set datetimeoriginal to createuate: "
loginfo -n "set datetimeoriginal to createdate: "
$setdate && exiftool -overwrite_original '-datetimeoriginal<createdate' -if '(not $datetimeoriginal and $createdate)' "$file"
else
loginfo -n "set datetimeoriginal to $newDateTimeOriginal"
$setdate && [ -n "$newDateTimeOriginal" ] && exiftool -overwrite_original "-DateTimeOriginal=$newDateTimeOriginal" -if '(not $datetimeoriginal)' "$file"
loginfo -n "set createdate to datetimeoriginal: "
$setdate && exiftool -overwrite_original '-createdate<datetimeoriginal' -if '(($createdate =~ "0000:00:00*" or not $createdate) and $datetimeoriginal)' "$file"
loginfo -n "set datetimeoriginal to createuate: "
loginfo -n "set datetimeoriginal to createdate: "
$setdate && exiftool -overwrite_original '-datetimeoriginal<createdate' -if '(not $datetimeoriginal and $createdate)' "$file"
fi
@ -181,12 +199,45 @@ run_fix () {
case $move in
true)
echo move to ${dest}/${MIMEDEST}/%Y/%Y_%m
loginfo "$(exiftool '-Directory<DateTimeOriginal' -d ${dest}/${MIMEDEST}/%Y/%Y_%m -if '($datetimeoriginal)' "$file" 2>&1 |tee -a ${LOGFILE})"
if $movecreatedate ; then
loginfo "$(exiftool '-Directory<CreateDate' -d ${dest}/${MIMEDEST}/%Y/%Y_%m -if '($CreateDate)' "$file" 2>&1 |tee -a ${LOGFILE})"
else
loginfo "$(exiftool '-Directory<DateTimeOriginal' -d ${dest}/${MIMEDEST}/%Y/%Y_%m -if '($datetimeoriginal)' "$file" 2>&1 |tee -a ${LOGFILE})"
fi
;;
copy)
echo copy to ${dest}/${MIMEDEST}/%Y/%Y_%m
loginfo "$(exiftool -o . '-Directory<DateTimeOriginal' -d ${dest}/${MIMEDEST}/%Y/%Y_%m -if '($datetimeoriginal)' "$file" 2>&1 |tee -a ${LOGFILE})"
logwarn "$(readlink -f "$file"): $(exiftool -filename -if '(not ($datetimeoriginal or $createdate))' "$file")"
if $movecreatedate ; then
loginfo "$(exiftool -o . '-Directory<DateTimeOriginal' -d ${dest}/${MIMEDEST}/%Y/%Y_%m -if '($datetimeoriginal)' "$file" 2>&1 |tee -a ${LOGFILE})"
logwarn "$(readlink -f "$file"): $(exiftool -filename -if '(not ($datetimeoriginal or $createdate))' "$file")"
else
loginfo "$(exiftool -o . '-Directory<DateTimeOriginal' -d ${dest}/${MIMEDEST}/%Y/%Y_%m -if '($datetimeoriginal)' "$file" 2>&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<CreateDate' -d %Y%m%d_%H%M%S%%-c.%%e -if '($CreateDate)' "$file" 2>&1 | tee -a ${LOGFILE})"
else
loginfo "$(exiftool '-FileName<DateTimeOriginal' -d %Y%m%d_%H%M%S%%-c.%%e -if '($DateTimeOriginal)' "$file" 2>&1 | tee -a ${LOGFILE})"
fi
;;
rename)
echo move to ${dest}/${MIMEDEST}/%Y/%Y_%m
if $movecreatedate ; then
loginfo "$(exiftool -v '-FileName<CreateDate' -d ${dest}/${MIMEDEST}/%Y/%Y_%m/%Y%m%d_%H%M%S%%-c.%%e -if '($CreateDate)' "$file" 2>&1 | tee -a ${LOGFILE})"
else
loginfo "$(exiftool -v '-FileName<DateTimeOriginal' -d ${dest}/${MIMEDEST}/%Y/%Y_%m/%Y%m%d_%H%M%S%%-c.%%e -if '($DateTimeOriginal)' "$file" 2>&1 | tee -a ${LOGFILE})"
fi
;;
copyrename)
echo move to ${dest}/${MIMEDEST}/%Y/%Y_%m
if $movecreatedate ; then
loginfo "$(exiftool -o . '-FileName<CreateDate' -d ${dest}/${MIMEDEST}/%Y/%Y_%m/%Y%m%d_%H%M%S%%-c.%%e -if '($CreateDate)' "$file" 2>&1 | tee -a ${LOGFILE})"
else
loginfo "$(exiftool -o . '-FileName<DateTimeOriginal' -d ${dest}/${MIMEDEST}/%Y/%Y_%m/%Y%m%d_%H%M%S%%-c.%%e -if '($DateTimeOriginal)' "$file" 2>&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"