Last active
January 2, 2018 15:45
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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