gestion-de-commission/Convention photos/traitements/rphoto

81 lines
1.7 KiB
Bash
Executable file

#!/bin/bash
checkcommand()
{
local result
local command="$1"
which "$command" 1>/dev/null 2>&1
if [[ $? == 0 ]]; then
echo "$command requirement OK"
result=1
else
echo "$command requirement MISSING"
result=0
fi
return $result
}
help()
{
echo "Usage: tphoto [-n] [ -h | -f ] [ *.jpg ]"
echo "Rename jpg files using Exif Original Date/Time if exists."
echo " -h Display help."
echo " -f Force rename jpg files with Exif datetime or file datetime."
echo " -n Dry run."
}
doRename()
{
local filename=$(basename $1)
#echo "$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
echo "$filename IGNORED"
fi
}
# main
checkcommand "exiftool"
if [[ $? == 0 ]]; then
exit 1
else
checkcommand "jhead"
if [[ $? == 0 ]]; then
exit 1
fi
fi
if [[ $# == 0 ]]; then
find . -maxdepth 1 -type f -iname "*.jpg" | while read path
do
doRenameCarefully "$path"
done
elif [[ "$1" == "-h" ]]; then
help
elif [[ "$1" == "-f" && $# == 1 ]]; then
find . -maxdepth 1 -type f -iname "*.jpg" | while read path
do
doRename "$path"
done
elif [[ "$1" == "-f" && $# > 1 ]]; then
for filename do
if [[ "$filename" != "-f" ]]; then
doRename "$filename"
fi
done
else
for filename do
doRenameCarefully "$filename"
done
fi