3
# pictor-rename: a script for renaming pictures sensibly,
4
# prepending a timestamp YYYY-MM-DD_HH-MM-SS__*
6
# Copyright (C) 2013 Dustin Kirkland <dustin.kirkland@gmail.com>
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU Affero General Public License as published by
10
# the Free Software Foundation, version 3 of the License.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU Affero General Public License for more details.
17
# You should have received a copy of the GNU Affero General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
24
if [ ! -f "$1" ]; then
27
mod=$(exiftool -CreateDate -d %Y-%m-%d_%H-%M-%S__ "$1" | sed -e "s/.*: //") 2>/dev/null
28
if echo "${mod}" | grep -qs "^[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}_[0-9]\{2\}-[0-9]\{2\}-[0-9]\{2\}__"; then
29
# First, try to get create date from image headers
32
# Otherwise, use file modification timestamp
33
mod=$(stat -c %y "${i}")
37
t=$(echo "${t}" | sed -e "s/:/-/g")
43
if [ "$2" != "$3" ]; then
49
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}'
52
echo "INFO: Repairing file names..."
56
file=$(basename "${i}")
58
if [ "${file}" = "." ] || [ "$file" = ".." ]; then
61
elif [ ! -f "${dir}/${file}" ]; then
64
elif echo "${file}" | grep -qs "^[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}_[0-9]\{2\}-[0-9]\{2\}-[0-9]\{2\}__"; then
67
# TODO: Support --force, to update existing prefix
74
dest="${dir}/${prefix}${newfile}"
75
repair "${prefix}" "${dir}/${file}" "${dest}"