name-by-date.sh now falls back to 'Date and Time (original)' and similar.
authorW. Trevor King <wking@drexel.edu>
Wed, 11 May 2011 11:24:25 +0000 (07:24 -0400)
committerW. Trevor King <wking@drexel.edu>
Wed, 11 May 2011 16:12:06 +0000 (12:12 -0400)
posts/name-by-date/name-by-date.sh

index 66de6c5c26413fe330a93e037c0cb1351d27d846..abfbc4cabfd340a8ee649f440e20422fac2829ef 100755 (executable)
@@ -28,7 +28,19 @@ while [ -n "$1" ]; do
        FILE=$1
        TYPE=$(file "$FILE" | grep JPEG)
        if [ -n "$TYPE" ]; then
-               ASCII_DATE=$(exif -m -t 'Date and Time' "$FILE")  # 2010:07:02 08:36:20
+               FIELD_NAME='Date and Time'
+               ASCII_DATE=$(exif -m -t "$FIELD_NAME" "$FILE")  # 2010:07:02 08:36:20
+               if [ $? -ne 0 ]; then  # use similar field, e.g. 'Date and Time (original)'
+                       FIELD=$(exif -m "$FILE" | grep "$FIELD_NAME" | head -n1)
+                       FIELD_NAME=$(echo "$FIELD" | sed 's/\t.*//')
+                       if [ -z "$FIELD_NAME" ]; then
+                               echo "$FILE has no stored date"
+                               ASCII_DATE=""
+                       else
+                               echo "$FILE using date from $FIELD_NAME"
+                               ASCII_DATE=$(exif -m -t "$FIELD_NAME" "$FILE")  # 2010:07:02 08:36:20
+                       fi
+               fi
                DATE=$(echo "$ASCII_DATE" | sed 's/:/./g' | sed 's/ /./g')
                if [ -z "$DATE" ]; then
                        echo "$FILE has no stored date"