update different scripts

This commit is contained in:
flukx 2024-02-08 21:42:48 +01:00
parent b2e163ff43
commit 61eaf8f5c6
3 changed files with 5 additions and 323 deletions

View file

@ -1,322 +0,0 @@
#!/bin/sh
#todo: bei jeder Aenderung auch usage (doc) anpassen
#todo: translate entire script into english
# adds date taken in beginning of file name if jpg, .png, (not yet: .mp4, .mov, ...)
# Attention: there is a hard link to this script at the end!!! moving this script meens changing it
# options
# -h --help display help
# -a --noask --no-interactive do not prompt the user to confirm renaming
# -l --onlylog just logs what would have been done but not doing anything
# -o [file] --outputfile [file] specifies the output (log) file (standard is da.log)
# -v [file] --voutputfile [file] specifies the verbose output log file (standard dav.log)
# -q --quiet do not log
#Functions
vLog()
{
echo "$1" >> "$VLOGFILE"
}
log()
{
echo "$1" >> "$NVLOGFILE"
echo "$1" >> "$VLOGFILE"
}
rename()
# moves $1 to $2 if rn is 1, otherwise set variable new to $1
# log move on any case
{
if test -e "$2"
then
log "do not move \"$1\" to \"$2\" since it already exists."
else
log "rn \"$1\" to \"$2\""
if [ $rn -eq 1 ]
then
mv -- "$1" "$2"
else
new="$1"
fi
fi
}
remove()
# deletes $1 if rn is 1, otherwise only logging
{
if test -f "$1"
then
#echo "$1"
log "rm \"$1\""
if test $rn -eq 1
then
trash "$1"
fi
fi
}
usage()
# displays help message and exit
{
echo ""
echo "help page for $0"
echo "---------------------------------"
echo "this script should not be called directly but by the Wrapper script WrapperAddDateTaken.sh"
echo "Usage: bash $0 [OPTIONS] DIR"
echo " $0 adds the date the picture was taken or movie was filmed at the beginning of the file name."
echo ""
echo "options"
echo " -h, --help display this help"
echo " -a, --noask --no-interactive do not prompt the user to confirm renaming (standard is asking for each file)"
echo " -l, --onlylog just logs what would have been done but not doing anything"
echo " -o [file], --outputfile [file] specifies the output (log) file (standard is da.log)"
echo " -v [file], --voutputfile [file] specifies the verbose output log file (standard dav.log)"
echo " - q, --quiet do not log"
echo " -- finishes the list of options, next argument is taken as the dir"
#echo " -i, --image adds date taken in beginning of file name if jpg, .png, (not yet: .mp4, .mov, ...)"
echo ""
echo "error handling"
echo " if DIR is no valid directory, the scripts eith error code 1"
exit
}
folderloc()
# returns the argument as absolute path
# arg1: if arg1 starts with /, return arg1, otherwise return $(pwd)/arg1
{
case "$1" in
/* ) echo "$1"
break
;;
* ) echo "$(pwd)/$1"
break
;;
esac
}
# considering options
# saving all options to give them recursively
ops=""
# standard behavior: ask the user is file is to be renamed
# 0 meens not asking
ask=1
# standard behavior: actually rename
# 0 meens not renaming but just log what would have be done
rn=1
# standard behaviour: rename as usual
# 1 meens adding date taken to image and video files
# image=0
# the log file for verbose logging
#VLOGFILE="$1"
VLOGFILE="$(pwd)"/../rnv.log
# the log file for short logging
#NVLOGFILE="$2"
NVLOGFILE="$(pwd)"/../rn.log
#directory to be checked
dir="$(pwd)" # standard if not specified
# -n = string is non-zero length?
while test -n "$1" ; do
case $1 in
-h | --help ) usage;;
-o | --outputfile ) # ops="$ops -o ../$2"
shift
NVLOGFILE="$(folderloc "$1")"
;;
-v | --voutputfile ) #ops="$ops -v ../$2"
shift
VLOGFILE="$(folderloc "$1")"
;;
-q | --quiet ) VLOGFILE="/dev/null"
NVLOGFILE="/dev/null"
;;
-a | --noask | --no-interactive ) ops="$ops -a"
ask=0
;;
-l | --onlylog ) ops="$ops -l"
rn=0
;;
-- ) shift
dir="$(folderloc "$1")"
break
;;
* ) dir="$(folderloc "$1")"
break
;;
esac
shift # must be done in any case: the next argument is $1
done
# echo "options"
# echo "asking=$ask"
# echo "rename=$rn"
# echo "log file=$NVLOGFILE"
# echo "verbose log file=$VLOGFILE"
# echo "direc=$dir"
#for testing purposes:
# exit
addDates()
# adds the picture taken dates to all pictures and descends into subfolders
{
for fil in *
do
if test -d "$fil"
then
cd "$fil"
addDates
cd ..
vLog "went back to $(pwd)"
continue
#vLog "handle dir"
# * als einziger Dateiname kommt auch bei leerem Ordner vor
fi
if test -e "$fil" # file to be moved exists
then
: # ok, do what comes after fi
else
continue
fi
case "$fil" in
20[12][0-9]_[01][0-9]_[0-3][0-9]*)
vLog "dont rename bc already date there: $fil";;
*.[jJ][pP][gG]|*.[jJ][pP][eE][gG]|*.[pP][nN][gG]|*.[mM][oO][Vv]|*.mp4) #|*.3gp|*.[aA][vV][iI])
date=$(exiftool -dateFormat "%Y_%m_%d_%H%M%S" -CreateDate "$fil" | awk '{print $4}')
# -z length is zero
if test -z "$date"
then
vLog "the file has no creation date: $fil"
else
# remove SAM_Zahl
new="$(echo "$fil" | sed 's/SAM_[0-9]\{4\}//')"
# remove DSC_Zahl (e.g. Hollys camera)
new="$(echo "$new" | sed 's/DSC_[0-9]\{4\}//')"
# remove DSCZaahl
new="$(echo "$new" | sed 's/DSC[0-9]\{5\}//')"
# remove DSCFZahl
new="$(echo "$new" | sed 's/DSCF[0-9]\{4\}//')"
# remove DSCIZahl
new="$(echo "$new" | sed 's/DSCI[0-9]\{4\}//')"
# remove DSCNZahl
new="$(echo "$new" | sed 's/DSCN[0-9]\{4\}//')"
# remove IMGPZahl (e.g. Romy Fischers camera)
new="$(echo "$new" | sed 's/IMGP[0-9]\{4\}//')"
#remove Zah-Zahl_IMG
new="$(echo "$new" | sed 's/[0-9]\{3\}-[0-9]\{4\}_IMG//')"
# remove IMG_Daaatuum_Zeeiit (e.g. my smartphone)
new="$(echo "$new" | sed 's/IMG_20[0-9]\{6\}_[0-9]\{6\}//')"
# and VID_... and PANO... (e.g. Veros smartphone)
new="$(echo "$new" | sed 's/VID_20[0-9]\{6\}_[0-9]\{6\}//')"
# remove PXL_Daaatuum_Zeitmitms.PANO (e.g. Berits Pixel smartphone)
new="$(echo "$new" | sed 's/PXL_20[0-9]\{6\}_[0-9]\{9\}\.PANO//')"
# remove PXL_Daaatuum_Zeitmitms.NIGHT (e.g. Berits Pixel smartphone)
new="$(echo "$new" | sed 's/PXL_20[0-9]\{6\}_[0-9]\{9\}\.NIGHT//')"
# remove PXL_Daaatuum_Zeitmitms.LS (e.g. Berits Pixel smartphone)
new="$(echo "$new" | sed 's/PXL_20[0-9]\{6\}_[0-9]\{9\}\.LS//')"
# remove PXL_Daaatuum_Zeitmitms.MP (e.g. Berits Pixel smartphone)
new="$(echo "$new" | sed 's/PXL_20[0-9]\{6\}_[0-9]\{9\}\.MP//')"
# remove PXL_Daaatuum_Zeitmitms (e.g. Berits Pixel smartphone)
new="$(echo "$new" | sed 's/PXL_20[0-9]\{6\}_[0-9]\{9\}//')"
# remove PXL_Daaatuum_Zeitmitms.MP (e.g. Berits Pixel smartphone)
new="$(echo "$new" | sed 's/PXL_20[0-9]\{6\}_[0-9]\{9\}\.MP//')"
# remove IMG_Zahl
new="$(echo "$new" | sed 's/IMG_[0-9]\{4\}//')"
# remove PZaaaahl
new="$(echo "$new" | sed 's/P[0-9]\{7\}//')"
# remove PCZaaahl
new="$(echo "$new" | sed 's/P[ABC][0-9]\{6\}//')"
# remove PICTZahl
new="$(echo "$new" | sed 's/PICT[0-9]\{4\}//')"
# remove SDCZaahl
new="$(echo "$new" | sed 's/SDC[0-9]\{5\}//')"
# remove RIMGZahl
new="$(echo "$new" | sed 's/RIMG[0-9]\{4\}//')"
# remove Zaaaaaahhhhhl (Paul)
new="$(echo "$new" | sed 's/[0-9]\{13\}//')"
# remove Zaaaaaaaaahl_0Mbelieb--.Z (my smart phone at second bluetooth copy)
new="$(echo "$new" | sed 's/[0-9]\{14\}_0M.\{6\}\--\.[1-9]//')"
# remove 0beliebi--.Z (my smart phone)
new="$(echo "$new" | sed 's/0.\{7\}--\.[1-9]//')"
# remove 0CLxbelb--.Z (my smart phone)
new="$(echo "$new" | sed 's/0CLx.\{6\}--\.[1-9]//')"
# remove zaaahhhl_zaahhl HDR~2 (Pauls Smartphone)
new="$(echo "$new" | sed 's/[0-9]\{8\}_[0-9]\{6\}\(_HDR\)\?\(~2\)\?//')"
# remove FotoZahl
new="$(echo "$new" | sed 's/Foto[0-9]\{4\}//')"
# remove zaaaahhhl_zaahhl (Baptistes smartphone)
new="$(echo "$new" | sed 's/[0-9]\{9\}_[0-9]\{6\}//')"
# remove zaaahhhl_zaahhl (Sushs smartphone)
new="$(echo "$new" | sed 's/[0-9]\{8\}_[0-9]\{6\}//')"
# remove [0-9A-Z]x8-([]x4-)x3-[]x12
new="$(echo "$new" | sed 's/[0-9A-Z]\{8\}-\([0-9A-Z]\{4\}-\)\{3\}[0-9A-Z]\{12\}//')"
# remove D7C_zahl (Kanthaus camera)
new="$(echo "$new" | sed 's/D7C_[0-9]\{4\}//')"
# remove _MG_zahl (Kanthaus Canon camera)
new="$(echo "$new" | sed 's/_MG_[0-9]\{4\}//')"
# hochzeitsbilder 180505_Za_Hochzeit (Z)
new="$(echo "$new" | sed 's/180505_[01][0-9]_Hochzeit ([0-9]*)/Hochzeit/')"
case "$new" in
_*|.*) ;; #tue nichts
*)
new="_$new";;
esac
new="$date$new" # date und _ haben keine Leerzeichen
# different jpeg extensions:
new="$(echo "$new" | sed 's/\.JPG/.jpg/g')"
new="$(echo "$new" | sed 's/\.JPEG/.jpg/g')"
new="$(echo "$new" | sed 's/\.jpeg/.jpg/g')"
# existiert eine Datei mit dem neuen Namen bereits?
# -e ist exist. die Datei schon?
if test -e "$new"
then
log "a file with name \"$new\" already exists, -> dont rename: $fil"
else
if test $ask -eq 0
then
rename "$fil" "$new"
else
# Abfrage ob man wirklich umbenennen will
echo "rename $fil to $new? enter, y, yes = yes"
read q
if test -z "$q" -o "$q" = "y" -o "$q" = "yes"
then
rename "$fil" "$new"
fi
fi
fi
fi
;;
*) vLog "dont rename bc no image: $fil"
esac
done
}
#actual script
# check if the argument is correct:
if test ! -d "$dir"
then
log "exiting bc there is no such dir as $dir"
#echo "exiting bc there is no such dir"
exit 1
fi
vLog "move to $dir"
cd "$dir"
addDates
# merke: in Bedingungsklammern [] von if muss am Anfang und am Ende ein " " (blank) stehen!!
# merke: Hinweise zu Bedingungen in if abrufbar unter "man test"
# merke: bei Zuweisungen mit = darf zwischen Variablenname und = kein Leerzweichen sein!
# (sonst wird Variablenname als command interpretiert)

View file

@ -77,9 +77,11 @@ REPLACEMENTS = {'\n': REPLACER,
r'"': "",
r"`": "",
r"´": "",
r"+": REPLACER + "und" + REPLACER,
r"&": REPLACER + "und" + REPLACER,
r"%": "Prozent" + REPLACER,
r"*": "x",
r"=": "-",
r"(with lyrics)": "",
r" ": REPLACER,
r"C#": "C_sharp",
@ -99,6 +101,7 @@ REPLACEMENTS = {'\n': REPLACER,
r"?": REPLACER,
r"": REPLACER,
r"": REPLACER,
r"!": REPLACER,
r"": REPLACER,
r"": REPLACER,
r">": REPLACER,

View file

@ -23,7 +23,8 @@ createdExtensions = ["aux", "fls", "log", "synctex.gz",
"out", "blg", "bcf", "lco", "vrb", "snm",
"nav", "auxlock", "upb", "upa", "glg", "glo",
"gls", "glsdefs", "idx", "ilg", "ind", "ist",
"fdb_latexmk", "pdf"]
"fdb_latexmk", "unq", "bbl", "blg", "loe"#, "pdf"
]
# first check for command line arguments
parser = ArgumentParser(description="Remove by latex created files.")