4 # improve the default ufraw configuration
8 # matches raw file names, used as case insensitive
9 RAW_REGEX='.*\.(arw|srf|sr2|crw|cr2|kdc|dcr|k25|raf|mef|mos|mrw|nef|orf|pef|ptx|dng|x3f|raw|r3d|3fr|erf)$'
11 # matches output file names, used as case insensitive
12 OUT_REGEX='.*\.(jpg|jpeg|png|tif|tiff|ppm)$'
14 # matches ufraw id file names, used as case sensitive
17 # matches xmp sidecar file names, used as case insensitive
20 # extract output file from ufraw id file
23 grep "<OutputFilename>.*</OutputFilename>" "$1" |sed -e 's|.*<OutputFilename>\(.*\)</OutputFilename>.*|\1|'
26 # extract input file from ufraw id file
29 grep "<InputFilename>.*</InputFilename>" "$1" |sed -e 's|.*<InputFilename>\(.*\)</InputFilename>.*|\1|'
32 add_xmp_from_sidecar ()
35 input=`get_input_from_id "$idfile"`
36 [ -f "$input" ] || return 1
39 dirname=${basename%/*}
40 xmp=`find "$dirname" -maxdepth 1 -path "$basename.*" -regextype posix-egrep -iregex "$XMP_REGEX" -print | head -n 1`
41 [ -f "$xmp" ] || return 1
43 output=`get_output_from_id "$idfile"`
45 [ -f "$output" ] || return 1
48 # passing the source file to exiv2 is unnecessary complicated
49 # do not change the orientation, ufraw resets it to 1
50 exiv2 insert -ixX -l "$dirname" -S "$xmpext" "$output"
51 exiv2 -M "set Xmp.tiff.Orientation 1" "$output"
54 # test if the id file has changed and the output needs to be refreshed
58 output=`get_output_from_id "$idfile"`
59 [ ! -f "$output" -o "$idfile" -nt "$output" ]
62 # refresh the output file specified by given id file, if necessary
63 process_ufraw_id_file ()
66 if id_file_changed "$idfile" ; then
67 ufraw-batch --overwrite "$idfile"
68 add_xmp_from_sidecar "$idfile"
72 # test for newly added raw files that were never processed
73 raw_file_not_processed ()
76 basename=${rawfile%.*}
77 dirname=${basename%/*}
78 outfiles=`find "$dirname" -maxdepth 1 -path "$basename.*" -regextype posix-egrep \( -iregex "$OUT_REGEX" -o -regex "$ID_REGEX" \) -print `
79 [ -z "$outfiles" ] # return true if no possible output file exists
81 # raw+jpeg pair created by the camera is considered processed,
82 # - this function returns false, the jpeg from camera is preserved and id file is not created
85 # process raw file for the first time
86 process_raw_file_default ()
89 if raw_file_not_processed "$rawfile" ; then
90 ufraw-batch --create-id=also \
96 idfile=${rawfile%.*}.ufraw
97 add_xmp_from_sidecar "$idfile"
101 # process all files listed in file $1
102 # if $2 is not empty, produce output for zenity --progress
110 [ -n "$use_zenity" ] && echo 0
112 if [ "$count" -gt 0 ] ; then
114 [ -f "$file" ] || continue
115 if echo "$file"|grep -E -q -i "$RAW_REGEX" ; then
116 process_raw_file_default "$file"
117 elif echo "$file"|grep -E -q "$ID_REGEX" ; then
118 process_ufraw_id_file "$file"
124 # the function can end at the 'echo' command with broken pipe
125 # if it is cancelled via zenity
126 [ -n "$use_zenity" ] && echo $((n * 100 / count))
130 [ -n "$use_zenity" ] && echo 100
133 # process all files in directories $@, including subdirectories
134 # processing is controlled by zenity dialogs if $DISPLAY is set
137 list=`mktemp /tmp/geeqie-ufraw-list.XXXXXXXXXX` || exit 1
139 find "$@" -regextype posix-egrep -iregex "$RAW_REGEX" -print | while read rawfile ; do
140 raw_file_not_processed "$rawfile" && echo "$rawfile"
143 #refresh output from changed id files
144 find "$@" -regextype posix-egrep -regex "$ID_REGEX" -print | while read idfile ; do
145 id_file_changed "$idfile" && echo "$idfile"
148 if [ -n "$DISPLAY" ] ; then
150 zenity --list --title "Files to proceed" --text "Files to proceed" --column "Files" <$list ; then
151 process_list $list with_zenity | zenity --progress --auto-close
153 zenity --info --title "All files are up-to-date" --text "All files are up-to-date"
166 RAW file collection maintenance tool
170 geeqie-ufraw [raw file | id file] ...
171 geeqie-ufraw --recursive [dir] ...
172 geeqie-ufraw -h | --help
174 This script searches for new RAW files or for modified UFRaw
175 ID files and process them with ufraw-batch. It can work either
176 on individual files or on whole directory.
177 The functions are designed to be usable from Geeqie menu.
187 verbose=yes #fixme: not used yet
200 if [ $# -lt 1 ] ; then
205 if [ -n "$recursive" ] ; then
206 # recursive processing of directories
209 list=`mktemp /tmp/geeqie-ufraw-list.XXXXXXXXXX` || exit 1
210 for file in "$@" ; do
211 echo "$file" |sed -e "s|^\([^/]\)|$PWD/\1|"