diff options
Diffstat (limited to 'misc_scipts/nef_update_from_xmp')
-rwxr-xr-x | misc_scipts/nef_update_from_xmp | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/misc_scipts/nef_update_from_xmp b/misc_scipts/nef_update_from_xmp new file mode 100755 index 0000000..b897cf2 --- /dev/null +++ b/misc_scipts/nef_update_from_xmp @@ -0,0 +1,84 @@ +#!/bin/bash +# SPDX-FileCopyrightText: 2023 Brian Woods +# SPDX-License-Identifier: GPL-2.0-or-later + +# ------------------------------------------------------------------ +# an exiftool rating updater +# This tool reads in xmp files from darktable and updates the +# orginal NEF file with the xmp file's rating. This is so when +# exporting darktable pictures into lightroom, the rating is +# imported into lightroom +# ------------------------------------------------------------------ + +VERSION=0.1.0 +USAGE="Usage: `basename "$0"` -bh <NEF file(s)>\n" +USAGE+="\t-b => backup orginals\n" +USAGE+="\t-r => remove xmp after updating\n" +USAGE+="\t-h => help" + + +BACKUP="-overwrite_original" +REMOVE=false + +if [ $# == 0 ] ; then + echo -e $USAGE + exit 1; +fi + +while getopts ":rbh" optname ; do + case "$optname" in + "v") + echo "Version $VERSION" + exit 0; + ;; + "b") + BACKUP= + ;; + "r") + REMOVE=true + ;; + "h") + echo -e $USAGE + exit 0; + ;; + "?") + echo "Unknown option $OPTARG" + exit 0; + ;; + ":") + echo "No argument value for option $OPTARG" + exit 0; + ;; + *) + echo "Unknown error while processing options" + exit 0; + ;; + esac +done + +shift $(($OPTIND - 1)) + +for NEFFILE in "$@" ; do + if [ ! -f ${NEFFILE} ] ; then + echo "${NEFFILE} doesn't exist, skipping" + continue; + fi + + XMPFILE="${NEFFILE}.xmp" + if [ ! -f ${XMPFILE} ] ; then + echo "${XMPFILE} doesn't exist, skipping" + continue; + fi + + exiftool ${BACKUP} -tagsFromFile ${XMPFILE} -Rating ${NEFFILE} + RV=$? + + if (($RV > 0)) ; then + echo "Updating rating from ${XMPFILE} to ${NEFFILE} failed" + continue + fi + + if [ "${REMOVE}" = true ] ; then + rm ${XMPFILE} + fi +done |