]> permondes.de Git - Pictureviewer2.git/blame - SoPi
Initial release
[Pictureviewer2.git] / SoPi
CommitLineData
7bb60213 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
12FN_List="SoPiList.out"
13EXIF_List="SoPiEXIF.out"
14Sorted_EXIF_List="SoPiEXIFS.out"
15PictureList="PictureList.txt"
16Pic_PATH=${1:-"Fotos"}"/"
17echo $Pic_PATH
18#Pic_PATH="$1/"
19
20# make sure file PictureList does not exist! To avoid overwriting existing data
21if [ -s "$PictureList" ]
22 then
23 echo ***Error: File $PictureList already exists
24 exit
25fi
26
27# List all pictures in the current directory and sub-directories
28echo Finding files...
29find "$Pic_PATH" -type f > "$FN_List"
30
31# read this file and add EXIF data
32echo Finding EXIF data...
33while read filename
34do
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
46done < "$FN_List"
47
48# sort by date, ignore separation characters in date (":" for EXIF, "-" for stat)
49echo Sorting filenames by date, then filename...
50sort --field-separator=" " --key=2 -d -o $Sorted_EXIF_List $EXIF_List
51
52echo Creating file $PictureList ...
53echo 'var pictureString = (` \' > "$PictureList"
54mawk -F\" '{printf "<figure><img src=\"%s\" /><figcaption>%s</figcaption></figure>\n", $2, $4}' $Sorted_EXIF_List >> "$PictureList"
55echo '`);' >> "$PictureList"
56
57echo cleaning up ...
58rm -f $EXIF_List
59rm -f $FN_List
60rm -f $Sorted_EXIF_List
61
62echo ...done
63exit