From: W. Trevor King Date: Wed, 11 May 2011 11:24:25 +0000 (-0400) Subject: name-by-date.sh now falls back to 'Date and Time (original)' and similar. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=37b4ae0ea5a5cba4f132c7d7e61183d423c330a0;p=blog.git name-by-date.sh now falls back to 'Date and Time (original)' and similar. --- 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"