Initial commit
[scripts.git] / redatepic.sh
1 #!/bin/bash
2
3 #########################################################################
4 # START_IP_HEADER                                                       #
5 #                                                                       #
6 # This program is free software: you can redistribute it and/or modify  #
7 # it under the terms of the version 3 of the GNU General Public License #
8 # as published by the Free Software Foundation.                         #
9 #                                                                       #
10 # This program is distributed in the hope that it will be useful, but   #
11 # WITHOUT ANY WARRANTY; without even the implied warranty of            #
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      #
13 # General Public License for more details.                              #
14 #                                                                       #
15 # You should have received a copy of the GNU General Public License     #
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.  #
17 #                                                                       #
18 # Written by and Copyright (C) Francois Fleuret                         #
19 # Contact <francois.fleuret@idiap.ch> for comments & bug reports        #
20 #                                                                       #
21 # END_IP_HEADER                                                         #
22 #########################################################################
23
24 while [ $1 ]; do
25
26     NAME=$1
27
28     REFERENCE=${NAME/MOV/JPG}
29
30     if [[ -f ${REFERENCE} ]]; then
31
32         TAG=$(exif --ifd=EXIF -t "Date and Time (original)" ${REFERENCE} | grep Value)
33
34         if [[ ${TAG} ]]; then
35             TIMESTAMP=$(echo ${TAG} | sed -e \
36                 "s/^ *Value: *\([0-9]*\):\([0-9]*\):\([0-9]*\) *\([0-9]*\):\([0-9]*\):\([0-9]*\).*$/\1\2\3\4\5.\6/")
37             touch -t $TIMESTAMP ${NAME}
38             ls -l ${NAME}
39         else
40             echo "++ No exif tag in ${NAME}, can not set the date properly."
41         fi
42
43     else
44         echo "++ Can not find a reference picture file for ${NAME}, can not set the date properly."
45     fi
46
47     shift
48
49 done