Added photos scripts.
This commit is contained in:
parent
67b46c99c0
commit
3eb70ff920
|
@ -0,0 +1,30 @@
|
||||||
|
#!/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
|
||||||
|
}
|
||||||
|
|
||||||
|
# main
|
||||||
|
if [[ "$1" == "-h" ]]; then
|
||||||
|
echo "The lowext command lowercases JPG file extensions in the current directory not recursively."
|
||||||
|
else
|
||||||
|
checkcommand rename
|
||||||
|
if [[ $? == 1 ]]; then
|
||||||
|
uppercaseCount=$(find -maxdepth 1 -name '*.JPG' | wc -l)
|
||||||
|
if [[ $uppercaseCount > 0 ]]; then
|
||||||
|
rename 's/JPG/jpg/' *.JPG
|
||||||
|
fi
|
||||||
|
echo ".JPG -> .jpg: $uppercaseCount"
|
||||||
|
fi
|
||||||
|
fi
|
|
@ -1,41 +1,78 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
function checkJhead()
|
checkcommand()
|
||||||
{
|
{
|
||||||
local result
|
local result
|
||||||
local check=$(which ant)
|
local command="$1"
|
||||||
if [[ "$check" =~ ^/.* ]]; then
|
which "$command" 1>/dev/null 2>&1
|
||||||
echo "jhead requirement OK"
|
if [[ $? == 0 ]]; then
|
||||||
|
echo "$command requirement OK"
|
||||||
result=1
|
result=1
|
||||||
else
|
else
|
||||||
echo "jhead requirement MISSING"
|
echo "$command requirement MISSING"
|
||||||
result=0
|
result=0
|
||||||
fi
|
fi
|
||||||
return $result
|
return $result
|
||||||
}
|
}
|
||||||
|
|
||||||
# main
|
help()
|
||||||
|
{
|
||||||
|
echo "Usage:"
|
||||||
|
echo " tphoto -h Display help."
|
||||||
|
echo " tphoto Rename jpg files from current directory with Exif datetime."
|
||||||
|
echo " tphoto *.jpg Rename files in parameter with Exif datetime."
|
||||||
|
echo " tphoto -f Rename jpg files from current directory with Exif datetime or file datetime."
|
||||||
|
echo " tphoto -f *.jpg Rename files in parameter with Exif datetime or file datetime."
|
||||||
|
}
|
||||||
|
|
||||||
# Lowercase extension.
|
renameFromDirectoryWithExifOnly()
|
||||||
uppercaseCount=$(find -maxdepth 1 -name '*.JPG' | wc -l)
|
{
|
||||||
if [[ $uppercaseCount > 0 ]]; then
|
find . -maxdepth 1 -type f -iname "*.jpg" | while read path
|
||||||
rename 's/JPG/jpg/' *.JPG
|
do
|
||||||
fi
|
filename=$(basename $path)
|
||||||
echo ".JPG -> .jpg: $uppercaseCount"
|
#echo "$filename"
|
||||||
|
if [[ $(jhead $filename | grep -c Date) == 1 ]]; then
|
||||||
# Rename.
|
|
||||||
checkJhead
|
|
||||||
if [[ $? == 1 ]]; then
|
|
||||||
count=0
|
|
||||||
for filename in $(ls *.jpg); do
|
|
||||||
#echo "==== $filename"
|
|
||||||
if [[ $(jhead $filename | grep Date) =~ ^Date.* ]]; then
|
|
||||||
#echo "yop $filename"
|
#echo "yop $filename"
|
||||||
jhead -n%Y%m%d-%H%M%S "$filename"
|
jhead -n%Y%m%d-%H%M%S "$filename"
|
||||||
let "count+=1"
|
else
|
||||||
|
echo "$filename IGNORED"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
renameFromDirectory()
|
||||||
|
{
|
||||||
|
find . -maxdepth 1 -type f -iname "*.jpg" | while read path
|
||||||
|
do
|
||||||
|
filename=$(basename $path)
|
||||||
|
#echo "$filename"
|
||||||
|
jhead -n%Y%m%d-%H%M%S "$filename"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# main
|
||||||
|
if [[ $# == 0 ]]; then
|
||||||
|
renameFromDirectoryWithExifOnly
|
||||||
|
elif [[ "$1" == "-h" ]]; then
|
||||||
|
help
|
||||||
|
elif [[ "$1" == "-f" && $# == 1 ]]; then
|
||||||
|
renameFromDirectory
|
||||||
|
elif [[ "$1" == "-f" && $# > 1 ]]; then
|
||||||
|
for filename do
|
||||||
|
if [[ "$filename" != "-f" ]]; then
|
||||||
|
#echo "$filename"
|
||||||
|
jhead -n%Y%m%d-%H%M%S "$filename"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
else
|
||||||
|
for filename do
|
||||||
|
#echo "$filename"
|
||||||
|
if [[ $(jhead $filename | grep -c Date) == 1 ]]; then
|
||||||
|
#echo "yop $filename"
|
||||||
|
jhead -n%Y%m%d-%H%M%S "$filename"
|
||||||
|
else
|
||||||
|
echo "$filename IGNORED"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
echo "Renamed: $count"
|
|
||||||
else
|
|
||||||
echo "KO"
|
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue