/usr/bin/pictor-rename is in pictor-unload 2.27-0ubuntu1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | #!/bin/sh -e
#
# pictor-rename: a script for renaming pictures sensibly,
# prepending a timestamp YYYY-MM-DD_HH-MM-SS__*
# on each filename
# Copyright (C) 2013 Dustin Kirkland <dustin.kirkland@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
get_prefix() {
local mod d t
_RET=
if [ ! -f "$1" ]; then
return
fi
mod=$(exiftool -CreateDate -d %Y-%m-%d_%H-%M-%S__ "$1" | sed -e "s/.*: //") 2>/dev/null
if echo "${mod}" | grep -qs "^[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}_[0-9]\{2\}-[0-9]\{2\}-[0-9]\{2\}__"; then
# First, try to get create date from image headers
_RET="${mod}"
else
# Otherwise, use file modification timestamp
mod=$(stat -c %y "${i}")
mod=${mod%%.*}
d=${mod%% *}
t=${mod##* }
t=$(echo "${t}" | sed -e "s/:/-/g")
_RET="${d}_${t}__"
fi
}
repair() {
if [ "$2" != "$3" ]; then
mv "$2" "$3"
fi
}
progress() {
echo $1 $2 | awk '{printf "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b[%s/%s] %0.0f%%", $1, $2, 100 * $1 / $2}'
}
echo "INFO: Repairing file names..."
j=0
for i in $@; do
j=$((j+1))
file=$(basename "${i}")
dir=$(dirname "${i}")
if [ "${file}" = "." ] || [ "$file" = ".." ]; then
progress ${j} $#
continue
elif [ ! -f "${dir}/${file}" ]; then
progress ${j} $#
continue
elif echo "${file}" | grep -qs "^[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}_[0-9]\{2\}-[0-9]\{2\}-[0-9]\{2\}__"; then
progress ${j} $#
continue
# TODO: Support --force, to update existing prefix
#newfile=${file##*__}
else
newfile="${file}"
fi
get_prefix "${i}"
prefix="${_RET}"
dest="${dir}/${prefix}${newfile}"
repair "${prefix}" "${dir}/${file}" "${dest}"
progress ${j} $#
done
echo
|