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
|
#!/bin/sh
## @file
## @brief Sets file mtime to the Exif.Image.DateTime of the file
##
## $@ List of files to be processed
##
## Requires exiv2 or exiftool
##
if [ -z "$(command -v exiv2)" ]
then
if [ -z "$(command -v exiftool)" ]
then
zenity --title="Geeqie exif datetime to file" --info --width=200 --text="Neither exiv2 nor exiftran is installed" --window-icon=/usr/local/share/pixmaps/geeqie.png 2> /dev/null
exit 1
else
use_exiv2=false
fi
else
use_exiv2=true
fi
if ! zenity --title="Geeqie - exif datetime to file" --question --text "Set file datetime (mtime) to Exif.Image.DateTime\n\nContinue?" --width=300 --window-icon=/usr/local/share/pixmaps/geeqie.png
then
exit 0
fi
# exiv2 should be faster
if [ "$use_exiv2" = "true" ]
then
while [ $# -gt 0 ]
do
if date_time=$(exiv2 -g Exif.Image.DateTime -Pv "$1")
then
y_m_d_h_m_s=$(echo "$date_time" | tr ' ' ':')
y_m_d_h_m=$(echo "$y_m_d_h_m_s" | cut --delimiter ':' --fields '1 2 3 4 5' | tr --delete ':')
s=$(echo "$y_m_d_h_m_s" | cut --delimiter ':' --fields '6')
touch -m -t "$y_m_d_h_m.$s" "$1"
else
printf "Geeqie plugin exif-datetime-to-file -\nFile: %s does not have Exif.Image.DateTime\n" "$1"
fi
shift
done
else
while [ $# -gt 0 ]
do
if date_time=$(exiftool -t -createdate "$1")
then
y_m_d_h_m_s=$(echo "$date_time" | cut --characters '13-31' | tr ' ' ':')
y_m_d_h_m=$(echo "$y_m_d_h_m_s" | cut --delimiter ':' --fields '1 2 3 4 5' | tr --delete ':')
s=$(echo "$y_m_d_h_m_s" | cut --delimiter ':' --fields '6')
touch -m -t "$y_m_d_h_m.$s" "$1"
else
printf "Geeqie plugin exif-datetime-to-file -\nFile: %s does not have Exif.Image.DateTime\n" "$1"
fi
shift
done
fi
|