]> permondes.de Git - Pictureviewer2.git/blob - SoPi
e15bbebbe1ffa0c35b8e0196f3d8cda14c9c787c
[Pictureviewer2.git] / SoPi
1 #!/bin/bash
2 # Sort pictures by date
3 #
4 # filename list working file
5
6 #if [ -z "$1" ]
7 # then
8 # echo usage: SoPi picturedirectory
9 # exit
10 #fi
11
12 FN_List="SoPiList.out"
13 EXIF_List="SoPiEXIF.out"
14 Sorted_EXIF_List="SoPiEXIFS.out"
15 PictureList="PictureList.txt"
16 Pic_PATH=${1:-"Fotos"}"/"
17 echo $Pic_PATH
18 #Pic_PATH="$1/"
19
20 # make sure file PictureList does not exist! To avoid overwriting existing data
21 if [ -s "$PictureList" ]
22 then
23 echo ***Error: File $PictureList already exists
24 exit
25 fi
26
27 # List all pictures in the current directory and sub-directories
28 echo Finding files...
29 find "$Pic_PATH" -type f > "$FN_List"
30
31 # read this file and add EXIF data
32 echo Finding EXIF data...
33 while read filename
34 do
35 # grep the line that contains the date the picture was taken, ignore error messages
36 #### EXIF_Value=`exif -t DateTimeOriginal "$filename" 2>/dev/null | grep -H --label="$filename" Value`
37 EXIF_Value=`exiv2 -g Exif.Photo.DateTimeOriginal -Pv print "$filename" 2>/dev/null`
38 # stat uses "-" in the date, exiv2 ":"
39 EXIF_Value=`echo $EXIF_Value | sed -e {s/:/-/} -e {s/:/-/}`
40 # if no picture date available use last modification date of file
41 if [ -z "$EXIF_Value" ]
42 then
43 EXIF_Value=`stat --printf="%y" "$filename"`
44 fi
45 echo -e \""$filename"\" \"$EXIF_Value\" >> $EXIF_List
46 done < "$FN_List"
47
48 # sort by date, ignore separation characters in date (":" for EXIF, "-" for stat)
49 echo Sorting filenames by date, then filename...
50 sort --field-separator=" " --key=2 -d -o $Sorted_EXIF_List $EXIF_List
51
52 echo Creating file $PictureList ...
53 echo 'var pictureString = (` \' > "$PictureList"
54 mawk -F\" '{printf "<figure><img src=\"%s\" /><figcaption>%s</figcaption></figure>\n", $2, $4}' $Sorted_EXIF_List >> "$PictureList"
55 echo '`);' >> "$PictureList"
56
57 echo cleaning up ...
58 rm -f $EXIF_List
59 rm -f $FN_List
60 rm -f $Sorted_EXIF_List
61
62 echo ...done
63 exit