Deprecated:  The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
#! /bin/sh
#
#   exifstamp -- EXIFのタイムスタンプ情報をファイル名の先頭に付加
#
#   Usage: exifstamp [file]...
#
#	0.0: Apr. 29, 2006 by Dai ISHIJIMA (as exifname)
#	0.1: Oct. 13, 2010 (as exifstamp)
#	0.2: Dec. 18, 2015
#
export LC_ALL=C
checkbytes=4096
verbose=NO
action=YES
# オプションを調べる
while [ "$#" -gt 0 ]; do
    case x"$1" in
	x-n)
	    action=NO
	    shift
	    ;;
	x-v)
	    verbose=YES
	    shift
	    ;;
	x-*)
	    echo "Usage: $0 [-n] [-v] [file]..." 1>&2
	    exit 1
	    ;;
	x*)
	    break
	    ;;
    esac
done
# 実際にファイル名変更などを行わないときは実行するコマンドのみを表示
case x"$action" in
    xNO)
	verbose=YES
	;;
esac
# 処理するファイルは指定されている?
case x"$#" in
    x0)
	echo "Usage: $0 [-n] [-v] [file]..." 1>&2
	exit 1
	;;
esac
status=0
for p in "$@" ; do
	if [ ! -r $p ]; then
		echo "${0}: $p not found (or not readable)" 1>&2
		continue
	fi
	# ファイルの先頭を調べ、EXIF情報からタイムスタンプを得る
	stamp=`head -c $checkbytes $p | strings | grep -E '[0-9]{4}:[0-9]{2}:[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}' | head -1`
	case x"$stamp" in
	    x)
		# タイムスタンプ情報が空の場合は00000000000000
		#	YYYYMMDDhhmmss
		fstamp="00000000000000"
		;;
	    x[0-9]*)
		# ファイル名に付ける日付情報
		fstamp=`echo $stamp | tr -dc '[0-9]'`
		# touch(1) のタイムスタンプ形式に
		tstamp=`echo $stamp | tr -d ': ' | sed 's/\([0-9][0-9]\)$/.\1/'`
		newname="${fstamp}-${p}"
		case x"$verbose" in
		    xYES)
			echo cp "$p" "$newname"
			echo touch -t "$tstamp" "$newname"
			;;
		esac
		case x"$action" in
		    xYES)
			cp "$p" "$newname"
			touch -t "$tstamp" "$newname"
			;;
		esac
		;;
	esac
done
# EOF