Skip to content

Instantly share code, notes, and snippets.

@mniehe
Forked from crapp/dt_raw_autoexport.sh
Created June 19, 2022 03:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mniehe/fe86fd842499c0f3012ac49733629ac7 to your computer and use it in GitHub Desktop.
Save mniehe/fe86fd842499c0f3012ac49733629ac7 to your computer and use it in GitHub Desktop.
Darktable cli convert all files in provided locations
#!/usr/bin/env bash
# Simple bash script to automate raw conversion using darktable cli
# Copyright © 2021 C. Rapp
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# based on
# https://gist.github.com/ruzickap/5b0d68d985f9cbca84acb49be5d2b0b5
shopt -s expand_aliases
DIR_EXPORT="dark_autoexport"
echo "Working directory $1"
cd $1
if [ ! -d "${DIR_EXPORT}" ]; then
echo "Export directory does not exist"
exit 3
fi
CNT=0
xmp_array=(`find ./ -maxdepth 1 -name "*.xmp" -printf "%f "`)
if [ ${#xmp_array[@]} -gt 0 ]; then
echo "Found ${#xmp_array[@]} files"
else
echo "WARNING -- NO XMP FILES FOUND"
exit 4
fi
# exit 0
# for XMP_FILE in *.xmp; do
for XMP_FILE in "${xmp_array[@]}"; do
RAW_FILE=`awk -F \" '/xmpMM:DerivedFrom=/ { print $2 }' $XMP_FILE`
RAW_FILE_NAME="${XMP_FILE%.*}"
FILE_NAME="${RAW_FILE%.*}"
echo "*** $XMP_FILE [$RAW_FILE] [$FILE_NAME]"
if [ "$RAW_FILE_NAME" != "$RAW_FILE" ]; then
echo "Raw file name mentioned in xmp (xmpMM:DerivedFrom) file doesn't match the raw file taken from \"$RAW_FILE_NAME\" !"
exit 1
fi
test -f $RAW_FILE || ( echo "$RAW_FILE does not exists !"; exit 2 )
test -f "${FILE_NAME}.jpg" && rm -v "${DIR_EXPORT}/${FILE_NAME}.jpg"
# 2> >(grep -v Gtk-WARNING >&2) >> Filter nasty Gtk warnings
darktable-cli --verbose "${RAW_FILE}" "${XMP_FILE}" "${DIR_EXPORT}/${FILE_NAME}.jpg" \
--core --conf plugins/imageio/format/jpeg/quality=90 2> >(grep -v Gtk-WARNING >&2)
# original filename plus date and a counter
exiftool -v '-filename<CreateDate' -d %f_%Y%m%d-%H%M%S%%-c.%%le \
"-filemodifydate<datetimeoriginal#" "${DIR_EXPORT}/${FILE_NAME}.jpg"
let "CNT+=1"
done
echo "--------------------------------------------------"
echo "Exported [${CNT}] files"
echo "--------------------------------------------------"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment