Add dt-import-geeqie-ratings

This commit is contained in:
Corrado Primier 2020-03-08 21:55:44 +00:00
parent cdd82136e0
commit d881964832

38
bin/dt-import-geeqie-ratings Executable file
View File

@ -0,0 +1,38 @@
#!/bin/sh
set -e -u
SCRIPTNAME=`basename "${0}"`
usage() {
echo "Import (and overwrite!) Geeqie ratings to Darktable"
echo "Usage: ${SCRIPTNAME} DIRECTORY"
}
if [ "${#}" -ne 1 ] || [ ! -d "${1}" ] ; then
usage
exit 1
fi
# Don't touch XMP files while Darktable is running
[ "`pidof darktable`" ] && { echo "Error: Darktable is running, aborting." ; false ; }
DARKTABLE_DIR=`realpath "${1}"`
GEEQIE_DIR=`realpath "${HOME}/.local/share/geeqie/metadata${DARKTABLE_DIR}"`
RATING_FIELD="xmp:Rating"
count=0
for dt_xmp in `find "${DARKTABLE_DIR}" -maxdepth 1 -type f -name '*.xmp'` ; do
img=`echo "\`basename ${dt_xmp}\`" | sed 's/\.xmp$//'`
gq_xmp="${GEEQIE_DIR}/${img}.gq.xmp"
if [ -r "${dt_xmp}" ] && [ -r "${gq_xmp}" ] ; then
gq_rating=`grep "${RATING_FIELD}" "$gq_xmp" | cut -d'"' -f2`
dt_rating=`grep "${RATING_FIELD}" "$dt_xmp" | cut -d'"' -f2`
if [ "${gq_rating}" ] && [ "${dt_rating}" ] && [ ${gq_rating} -ne ${dt_rating} ] ; then
((++count)) # Pre-increment because post-increment fails with 'set -e' :)
echo "counted"
sed -i 's/'${RATING_FIELD}'="'${dt_rating}'"/'${RATING_FIELD}'="'${gq_rating}'"/' "${dt_xmp}"
fi
fi
done
echo "${count} ratings imported. Remember to activate sidecar scanning at Darktable start-up."