| 
									
										
										
										
											2013-06-28 00:14:48 +04:00
										 |  |  | #!/bin/bash
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-03 07:24:37 +04:00
										 |  |  | # TODO make this runnable from anywhere... | 
					
						
							|  |  |  | #	- prepend paths with './' only if local/relative | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-01 11:47:55 +04:00
										 |  |  | # HACK: this is here to avoid using windows find... | 
					
						
							|  |  |  | PATH=/bin:$PATH | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | printhelp(){ | 
					
						
							| 
									
										
										
										
											2013-09-03 07:24:37 +04:00
										 |  |  | 	echo "Usage: `basename $0` [ARGUMENTS] [ARCHIVE_ROOT]" | 
					
						
							| 
									
										
										
										
											2013-09-01 11:47:55 +04:00
										 |  |  | 	echo | 
					
						
							| 
									
										
										
										
											2013-09-03 07:24:37 +04:00
										 |  |  | 	echo "Arguments:" | 
					
						
							|  |  |  | 	echo "	-h --help	- print this help and exit." | 
					
						
							|  |  |  | 	echo "	--common-previews PATH" | 
					
						
							|  |  |  | 	echo "			- build a single preview set at PATH." | 
					
						
							| 
									
										
										
										
											2013-09-01 11:47:55 +04:00
										 |  |  | 	echo | 
					
						
							| 
									
										
										
										
											2013-09-03 07:24:37 +04:00
										 |  |  | 	echo "	--skip-archive	- skip creating archive structure (use: exiftool)." | 
					
						
							|  |  |  | 	echo "	--skip-previews	- skip creating previews (use: vips)." | 
					
						
							|  |  |  | 	echo "	--skip-cache	- skip creating cache (use: buildcache)." | 
					
						
							|  |  |  | 	echo "	--skip-all	- same as setting all of the above." | 
					
						
							| 
									
										
										
										
											2013-09-01 11:47:55 +04:00
										 |  |  | 	echo | 
					
						
							| 
									
										
										
										
											2013-09-03 07:24:37 +04:00
										 |  |  | 	echo "NOTE: common preview path is relative to ARCHIVE_ROOT." | 
					
						
							|  |  |  | 	echo "NOTE: if no arguments are passed then this will process all directories" | 
					
						
							|  |  |  | 	echo "	in current location." | 
					
						
							| 
									
										
										
										
											2013-09-01 11:47:55 +04:00
										 |  |  | 	echo | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # process args... | 
					
						
							|  |  |  | while true ; do | 
					
						
							|  |  |  | 	case $1 in | 
					
						
							|  |  |  | 		-h|--help) | 
					
						
							|  |  |  | 			printhelp | 
					
						
							|  |  |  | 			exit | 
					
						
							|  |  |  | 			;; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		--common-previews) | 
					
						
							|  |  |  | 			COMMON_PREVIEWS="${2}/preview (RAW)" | 
					
						
							|  |  |  | 			shift | 
					
						
							|  |  |  | 			shift | 
					
						
							|  |  |  | 			;; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		--skip-archive) | 
					
						
							|  |  |  | 			SKIP_ARCHIVE=yes | 
					
						
							|  |  |  | 			echo skipping making archive... | 
					
						
							|  |  |  | 			shift | 
					
						
							|  |  |  | 			;; | 
					
						
							|  |  |  | 		--skip-previews) | 
					
						
							|  |  |  | 			SKIP_PREVIEWS=yes | 
					
						
							|  |  |  | 			echo skipping making previews... | 
					
						
							|  |  |  | 			shift | 
					
						
							|  |  |  | 			;; | 
					
						
							|  |  |  | 		--skip-cache) | 
					
						
							|  |  |  | 			SKIP_CACHE=yes | 
					
						
							|  |  |  | 			echo skipping making cache... | 
					
						
							|  |  |  | 			shift | 
					
						
							|  |  |  | 			;; | 
					
						
							|  |  |  | 		--skip-all) | 
					
						
							|  |  |  | 			SKIP_ARCHIVE=yes | 
					
						
							|  |  |  | 			echo skipping making archive... | 
					
						
							|  |  |  | 			SKIP_PREVIEWS=yes | 
					
						
							|  |  |  | 			echo skipping making previews... | 
					
						
							|  |  |  | 			SKIP_CACHE=yes | 
					
						
							|  |  |  | 			echo skipping making cache... | 
					
						
							|  |  |  | 			shift | 
					
						
							|  |  |  | 			;; | 
					
						
							| 
									
										
										
										
											2013-09-08 03:28:11 +04:00
										 |  |  | 		*) | 
					
						
							|  |  |  | 			break | 
					
						
							|  |  |  | 			;; | 
					
						
							| 
									
										
										
										
											2013-09-01 11:47:55 +04:00
										 |  |  | 	esac | 
					
						
							|  |  |  | done | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if [ -z "$1" ] ; then | 
					
						
							| 
									
										
										
										
											2013-07-03 03:14:40 +04:00
										 |  |  | 	ARCHIVE_ROOT="." | 
					
						
							| 
									
										
										
										
											2013-09-08 03:28:11 +04:00
										 |  |  | else | 
					
						
							|  |  |  | 	ARCHIVE_ROOT="$1" | 
					
						
							| 
									
										
										
										
											2013-07-03 03:14:40 +04:00
										 |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | echo "Doing: \"$ARCHIVE_ROOT\"" | 
					
						
							| 
									
										
										
										
											2013-06-28 00:14:48 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | METADATA_DIR="metadata" | 
					
						
							|  |  |  | RAW_PREVIEW_DIR="hi-res (RAW)" | 
					
						
							| 
									
										
										
										
											2013-06-28 18:37:15 +04:00
										 |  |  | PROCESSED_PREVIEW_DIR="preview" | 
					
						
							| 
									
										
										
										
											2013-06-28 00:14:48 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-28 18:37:15 +04:00
										 |  |  | PROCESSED_PREVIEW_NAME="%-:1d/${PROCESSED_PREVIEW_DIR}/%f.jpg" | 
					
						
							| 
									
										
										
										
											2013-06-28 00:14:48 +04:00
										 |  |  | PREVIEW_NAME="%-:1d/${RAW_PREVIEW_DIR}/%f.jpg" | 
					
						
							|  |  |  | JSON_NAME="%-:1d/${METADATA_DIR}/%f.json" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-28 03:48:16 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-29 04:14:45 +04:00
										 |  |  | # TODO do a version of this using exiv2... | 
					
						
							|  |  |  | #	- to be more flexible... | 
					
						
							|  |  |  | #	- check speed... | 
					
						
							|  |  |  | #	- give the user more options... | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2013-06-28 03:48:16 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | # XXX need to also copy jpg originals to the preview dir (things that  | 
					
						
							|  |  |  | #	were shot in jpeg in-camera)... | 
					
						
							| 
									
										
										
										
											2013-06-28 00:14:48 +04:00
										 |  |  | # XXX need to prevent overwriting of unchanged exif data... | 
					
						
							|  |  |  | #	when file exists?? | 
					
						
							| 
									
										
										
										
											2013-06-28 18:37:15 +04:00
										 |  |  | # XXX add PSD metadata extraction... | 
					
						
							| 
									
										
										
										
											2013-06-29 04:14:45 +04:00
										 |  |  | #	-execute '-FileModifyDate<DateTimeOriginal' -tagsfromfile @ \ | 
					
						
							|  |  |  | #		-srcfile "$PROCESSED_PREVIEW_NAME" -overwrite_original \ | 
					
						
							| 
									
										
										
										
											2013-06-28 18:37:15 +04:00
										 |  |  | # XXX keep file dates... | 
					
						
							| 
									
										
										
										
											2013-06-28 00:14:48 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-01 11:47:55 +04:00
										 |  |  | if [ -z $SKIP_ARCHIVE ] ; then | 
					
						
							|  |  |  | 	exiftool -if '$jpgfromraw' -b -jpgfromraw -w "$PREVIEW_NAME" \
 | 
					
						
							|  |  |  | 		-execute -if '$previewimage' -b -previewimage -w "$PREVIEW_NAME" \
 | 
					
						
							|  |  |  | 		-execute '-FileModifyDate<DateTimeOriginal' -tagsfromfile @ \
 | 
					
						
							|  |  |  | 			-srcfile "$PREVIEW_NAME" -overwrite_original \
 | 
					
						
							|  |  |  | 		-execute -j -w "$JSON_NAME" \
 | 
					
						
							|  |  |  | 		-common_args --ext jpg -r "./$ARCHIVE_ROOT" -progress | 
					
						
							|  |  |  | fi | 
					
						
							| 
									
										
										
										
											2013-06-28 00:14:48 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SIZE=900 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | COMPRESSION=90 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-03 03:14:40 +04:00
										 |  |  | # XXX remove this in production... | 
					
						
							| 
									
										
										
										
											2013-06-29 04:14:45 +04:00
										 |  |  | PATH=$PATH:/mnt/d/Program\ Files/vips/bin/ | 
					
						
							| 
									
										
										
										
											2013-06-28 00:14:48 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-01 11:47:55 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # makepreview SIZE IN [OUT [SIZE [COMPRESSION]]] | 
					
						
							|  |  |  | #  | 
					
						
							|  |  |  | # NOTE: SIZE and COMPRESSION will be set as follows (in order of priority): | 
					
						
							|  |  |  | #	- explicit argument | 
					
						
							|  |  |  | #	- global env var, if set | 
					
						
							|  |  |  | #	- hardcoded default value | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # XXX cahnge global var names to be less generic... | 
					
						
							| 
									
										
										
										
											2013-06-28 03:48:16 +04:00
										 |  |  | makepreview(){ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-01 11:47:55 +04:00
										 |  |  | 	# arguments... | 
					
						
							| 
									
										
										
										
											2013-06-28 03:48:16 +04:00
										 |  |  | 	SIZE="$1" | 
					
						
							|  |  |  | 	IN="$2" | 
					
						
							| 
									
										
										
										
											2013-09-01 11:47:55 +04:00
										 |  |  | 	# output dir... | 
					
						
							|  |  |  | 	if [ -z $OUT ] ; then | 
					
						
							|  |  |  | 		# default... | 
					
						
							|  |  |  | 		# XXX is this correct??? (not generic enough...) | 
					
						
							|  |  |  | 		OUT="${IN/hi-res\ /preview }" | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		OUT="$3" | 
					
						
							|  |  |  | 	fi | 
					
						
							|  |  |  | 	# size... | 
					
						
							|  |  |  | 	if [ -z $4 ] ; then | 
					
						
							|  |  |  | 		if [ -z $SIZE ] ; then | 
					
						
							|  |  |  | 			# default... | 
					
						
							|  |  |  | 			SIZE=900 | 
					
						
							|  |  |  | 		fi | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		SIZE=$4 | 
					
						
							|  |  |  | 	fi | 
					
						
							|  |  |  | 	# compression... | 
					
						
							|  |  |  | 	if [ -z $5 ] ; then | 
					
						
							|  |  |  | 		if [ -z $COMPRESSION ] ; then | 
					
						
							|  |  |  | 			# default... | 
					
						
							|  |  |  | 			COMPRESSION=90 | 
					
						
							|  |  |  | 		fi | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		COMPRESSION=$5 | 
					
						
							|  |  |  | 	fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-28 03:48:16 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-28 00:14:48 +04:00
										 |  |  | 	# create preview dir if it does not already exist... | 
					
						
							| 
									
										
										
										
											2013-07-03 01:44:03 +04:00
										 |  |  | 	DIR="`dirname \"./${OUT}\"`" | 
					
						
							|  |  |  | 	if ! [ -e "./$DIR" ] ; then | 
					
						
							|  |  |  | 		mkdir -p "./$DIR" | 
					
						
							| 
									
										
										
										
											2013-06-28 00:14:48 +04:00
										 |  |  | 	fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-28 00:23:04 +04:00
										 |  |  | 	# create previews... | 
					
						
							| 
									
										
										
										
											2013-07-03 01:44:03 +04:00
										 |  |  | 	if ! [ -e "./${OUT}" ] ; then | 
					
						
							| 
									
										
										
										
											2013-06-28 00:14:48 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-28 00:23:04 +04:00
										 |  |  | 		# get source size... | 
					
						
							| 
									
										
										
										
											2013-06-28 03:48:16 +04:00
										 |  |  | 		W=$(vips im_header_int width "$IN") | 
					
						
							|  |  |  | 		H=$(vips im_header_int height "$IN") | 
					
						
							| 
									
										
										
										
											2013-06-28 00:14:48 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-28 00:23:04 +04:00
										 |  |  | 		# NOTE: vips appends nasty unprintable \r's to values, so we need to clean them out... | 
					
						
							|  |  |  | 		W=${W//[![:digit:]]/} | 
					
						
							|  |  |  | 		H=${H//[![:digit:]]/} | 
					
						
							| 
									
										
										
										
											2013-06-28 00:14:48 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-28 00:23:04 +04:00
										 |  |  | 		# calculate the factor... | 
					
						
							|  |  |  | 		FACTOR=$(echo "scale = 4; if($H > $W) s = $H else s = $W ; s / $SIZE" | bc -l) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-28 03:48:16 +04:00
										 |  |  | 		echo "($FACTOR): ${OUT}:${COMPRESSION}" | 
					
						
							| 
									
										
										
										
											2013-06-28 00:14:48 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-03 01:44:03 +04:00
										 |  |  | 		vips im_shrink "./$IN" "./${OUT}:${COMPRESSION}" $FACTOR $FACTOR 2> /dev/null | 
					
						
							| 
									
										
										
										
											2013-09-01 11:47:55 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		touch -c -r "./$IN" "./${OUT}" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		echo "File already exists: ${OUT}" | 
					
						
							| 
									
										
										
										
											2013-06-28 00:14:48 +04:00
										 |  |  | 	fi | 
					
						
							| 
									
										
										
										
											2013-06-28 03:48:16 +04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-01 11:47:55 +04:00
										 |  |  | export SIZE COMPRESSION | 
					
						
							|  |  |  | export -f makepreview  | 
					
						
							| 
									
										
										
										
											2013-06-29 04:14:45 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-04 02:14:48 +04:00
										 |  |  | cd "./${ARCHIVE_ROOT}" | 
					
						
							| 
									
										
										
										
											2013-06-29 04:14:45 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-04 02:14:48 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-02 01:25:28 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-01 11:47:55 +04:00
										 |  |  | # make previews... | 
					
						
							|  |  |  | if [ -z $SKIP_PREVIEWS ] ; then | 
					
						
							|  |  |  | 	find . -path '*hi-res (RAW)/*.jpg' -exec bash -c 'makepreview "$SIZE" "{}"' \; | 
					
						
							|  |  |  | fi | 
					
						
							| 
									
										
										
										
											2013-07-04 02:14:48 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-02 01:25:28 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-01 11:47:55 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | # collect previews to one location... | 
					
						
							|  |  |  | if ! [ -z $COMMON_PREVIEWS ] ; then | 
					
						
							|  |  |  | 	if ! [ -e "./$COMMON_PREVIEWS" ] ; then | 
					
						
							|  |  |  | 		mkdir -p "./$COMMON_PREVIEWS" | 
					
						
							|  |  |  | 	fi | 
					
						
							| 
									
										
										
										
											2013-09-08 04:00:23 +04:00
										 |  |  | 	find . -type d -name 'preview (RAW)' -exec mv "{}" "./$COMMON_PREVIEWS" \; | 
					
						
							| 
									
										
										
										
											2013-09-01 11:47:55 +04:00
										 |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # build cache... | 
					
						
							|  |  |  | if [ -z $SKIP_CACHE ] ; then | 
					
						
							| 
									
										
										
										
											2013-09-08 04:00:23 +04:00
										 |  |  | 	find . -type d -name 'preview (RAW)' -exec buildcache "{}" \; | 
					
						
							| 
									
										
										
										
											2013-07-04 02:14:48 +04:00
										 |  |  | fi | 
					
						
							| 
									
										
										
										
											2013-06-28 03:48:16 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-28 00:14:48 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-01 11:47:55 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-29 04:14:45 +04:00
										 |  |  | # vim:set nowrap nospell : |