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

82 lines
1.7 KiB
Plaintext
Raw Normal View History

2022-07-19 15:33:35 +02:00
#!/bin/bash
2022-07-07 23:09:06 +02:00
2022-07-08 02:00:59 +02:00
checkcommand()
2022-07-07 23:09:06 +02:00
{
local result
2022-07-08 02:00:59 +02:00
local command="$1"
which "$command" 1>/dev/null 2>&1
if [[ $? == 0 ]]; then
echo "$command requirement OK"
2022-07-07 23:09:06 +02:00
result=1
else
2022-07-08 02:00:59 +02:00
echo "$command requirement MISSING"
2022-07-07 23:09:06 +02:00
result=0
fi
return $result
}
2022-07-08 02:00:59 +02:00
help()
{
2022-07-19 15:33:35 +02:00
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."
2022-07-08 02:00:59 +02:00
}
2022-07-07 23:09:06 +02:00
2022-07-19 15:33:35 +02:00
doRename()
2022-07-08 02:00:59 +02:00
{
2022-07-19 15:33:35 +02:00
local filename=$(basename $1)
#echo "$filename"
jhead -nIMG%Y%m%d-%H%M%S "$filename"
2022-07-08 02:00:59 +02:00
}
2022-07-07 23:09:06 +02:00
2022-07-19 15:33:35 +02:00
doRenameCarefully()
2022-07-08 02:00:59 +02:00
{
2022-07-19 15:33:35 +02:00
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
2022-07-08 02:00:59 +02:00
}
# main
2022-07-19 15:33:35 +02:00
checkcommand "exiftool"
if [[ $? == 0 ]]; then
exit 1
else
checkcommand "jhead"
if [[ $? == 0 ]]; then
exit 1
fi
fi
2022-07-08 02:00:59 +02:00
if [[ $# == 0 ]]; then
2022-07-19 15:33:35 +02:00
find . -maxdepth 1 -type f -iname "*.jpg" | while read path
do
doRenameCarefully "$path"
done
2022-07-08 02:00:59 +02:00
elif [[ "$1" == "-h" ]]; then
help
elif [[ "$1" == "-f" && $# == 1 ]]; then
2022-07-19 15:33:35 +02:00
find . -maxdepth 1 -type f -iname "*.jpg" | while read path
do
doRename "$path"
done
2022-07-08 02:00:59 +02:00
elif [[ "$1" == "-f" && $# > 1 ]]; then
for filename do
if [[ "$filename" != "-f" ]]; then
2022-07-19 15:33:35 +02:00
doRename "$filename"
2022-07-07 23:09:06 +02:00
fi
done
else
2022-07-08 02:00:59 +02:00
for filename do
2022-07-19 15:33:35 +02:00
doRenameCarefully "$filename"
2022-07-08 02:00:59 +02:00
done
2022-07-07 23:09:06 +02:00
fi
2022-07-19 15:33:35 +02:00