Improved rphoto.

This commit is contained in:
Christian P. MOMON 2022-07-19 15:33:35 +02:00
parent 35cca4cf75
commit fa878851eb
1 changed files with 41 additions and 38 deletions

View File

@ -17,62 +17,65 @@ checkcommand()
help() help()
{ {
echo "Usage:" echo "Usage: tphoto [-n] [ -h | -f ] [ *.jpg ]"
echo " tphoto -h Display help." echo "Rename jpg files using Exif Original Date/Time if exists."
echo " tphoto Rename jpg files from current directory with Exif datetime." echo " -h Display help."
echo " tphoto *.jpg Rename files in parameter with Exif datetime." echo " -f Force rename jpg files with Exif datetime or file datetime."
echo " tphoto -f Rename jpg files from current directory with Exif datetime or file datetime." echo " -n Dry run."
echo " tphoto -f *.jpg Rename files in parameter with Exif datetime or file datetime."
} }
renameFromDirectoryWithExifOnly() doRename()
{ {
find . -maxdepth 1 -type f -iname "*.jpg" | while read path local filename=$(basename $1)
do
filename=$(basename $path)
#echo "$filename" #echo "$filename"
if [[ $(jhead $filename | grep -c Date) == 1 ]]; then
#echo "yop $filename"
jhead -nIMG%Y%m%d-%H%M%S "$filename" jhead -nIMG%Y%m%d-%H%M%S "$filename"
}
doRenameCarefully()
{
local filename=$(basename $1)
#echo "$filename"
if [[ $(exiftool $filename | grep -c "Date/Time Original") > 0 ]]; then
#echo "yop $filename"
doRename "$filename"
else else
echo "$filename IGNORED" echo "$filename IGNORED"
fi fi
done
} }
renameFromDirectory()
{
find . -maxdepth 1 -type f -iname "*.jpg" | while read path
do
filename=$(basename $path)
#echo "$filename"
jhead -nIMG%Y%m%d-%H%M%S "$filename"
done
}
# main # main
checkcommand "exiftool"
if [[ $? == 0 ]]; then
exit 1
else
checkcommand "jhead"
if [[ $? == 0 ]]; then
exit 1
fi
fi
if [[ $# == 0 ]]; then if [[ $# == 0 ]]; then
renameFromDirectoryWithExifOnly find . -maxdepth 1 -type f -iname "*.jpg" | while read path
do
doRenameCarefully "$path"
done
elif [[ "$1" == "-h" ]]; then elif [[ "$1" == "-h" ]]; then
help help
elif [[ "$1" == "-f" && $# == 1 ]]; then elif [[ "$1" == "-f" && $# == 1 ]]; then
renameFromDirectory find . -maxdepth 1 -type f -iname "*.jpg" | while read path
do
doRename "$path"
done
elif [[ "$1" == "-f" && $# > 1 ]]; then elif [[ "$1" == "-f" && $# > 1 ]]; then
for filename do for filename do
if [[ "$filename" != "-f" ]]; then if [[ "$filename" != "-f" ]]; then
#echo "$filename" doRename "$filename"
jhead -nIMG%Y%m%d-%H%M%S "$filename"
fi fi
done done
else else
for filename do for filename do
#echo "$filename" doRenameCarefully "$filename"
if [[ $(jhead $filename | grep -c Date) == 1 ]]; then
#echo "yop $filename"
jhead -nIMG%Y%m%d-%H%M%S "$filename"
else
echo "$filename IGNORED"
fi
done done
fi fi