From 37b4ae0ea5a5cba4f132c7d7e61183d423c330a0 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 11 May 2011 07:24:25 -0400 Subject: [PATCH] name-by-date.sh now falls back to 'Date and Time (original)' and similar. --- posts/name-by-date/name-by-date.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/posts/name-by-date/name-by-date.sh b/posts/name-by-date/name-by-date.sh index 66de6c5..abfbc4c 100755 --- a/posts/name-by-date/name-by-date.sh +++ b/posts/name-by-date/name-by-date.sh @@ -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" -- 2.26.2