Skip to content

Instantly share code, notes, and snippets.

@vmassuchetto
Last active January 2, 2018 15:45
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 vmassuchetto/edad377425c1274cb6f9e432e9a74de2 to your computer and use it in GitHub Desktop.
Save vmassuchetto/edad377425c1274cb6f9e432e9a74de2 to your computer and use it in GitHub Desktop.
Syncronize Shotwell photos directories moving files to the exposure time adjusted in the application
#!/bin/bash
DBFILE=~/.local/share/shotwell/data/photo.db
PHOTODIR="~/photos"
STRUCTURE="%Y/%m"
UPDATE="$(mktemp -d "${TMPDIR:-/tmp/}$(basename 0).XXXXXXXXXXXX")/update.sql"
echo '' > $UPDATE
PHOTODIR=${PHOTODIR/#\~/$HOME}
sqlite3 $DBFILE \
"SELECT 'PhotoTable'|| ' '||id||' '||exposure_time||' '||filename FROM PhotoTable
UNION
SELECT 'VideoTable'||' '||id||' '||exposure_time||' '||filename FROM VideoTable" |
while read TABLE ID EXPOSURE_TIME SRC; do
DST="$PHOTODIR/$(date -d @$EXPOSURE_TIME +$STRUCTURE)/$(basename "$SRC")"
if [ ! -f "$DST" ]; then
mkdir -p $(dirname $DST)
mv -vi "$SRC" "$DST"
echo "UPDATE $TABLE SET filename='$DST' WHERE id=$ID;" >> $UPDATE
fi
done
echo "Updating database using file $UPDATE"
sqlite3 $DBFILE < $UPDATE
echo "Deleting empty directories"
find $PHOTODIR -depth -type d -empty -delete
echo "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment