Skip to content

Instantly share code, notes, and snippets.

@inukshuk
Created November 15, 2019 08:36
Show Gist options
  • Save inukshuk/f0dbcd4005dfd4bdfb2b2c0a481ac37b to your computer and use it in GitHub Desktop.
Save inukshuk/f0dbcd4005dfd4bdfb2b2c0a481ac37b to your computer and use it in GitHub Desktop.
Find Missing Tropy Photos
#!/bin/bash
set -e
if [ $# -lt 2 ]; then
echo
echo "Usage: $0 PROJECT SEARCH_PATH"
echo "Find missing photos in your Tropy project"
echo
echo "Please specify the Tropy PROJECT file and a folder as the SEARCH_PATH"
echo
exit 1
fi
PROJECT="$1"
SQLITE="sqlite3 -noheader -csv"
find "$2" -type f | \
while read file; do
# macOS
checksum=$(md5 -q "$file")
# Linux
#file=$(realpath file)
#checksum=$(md5sum "$file" | cut -f 1 -d " ")
$SQLITE $PROJECT "select id, path from photos where checksum='$checksum'" | \
while IFS=, read id original; do
original=${original%\"}
original=${original#\"}
if [ ! -f "$original" ]; then
# Here we have photos where the original file path stored in the
# project is missing and we have found a file in the search path
# with the same checksum as the missing file.
update="UPDATE photos SET path=\"$file\" WHERE id=$id;"
# Update project db (make a backup first!)
# $SQLITE $PROJECT $update
# Or just print the update script
echo $update
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment