Created
November 15, 2019 08:36
-
-
Save inukshuk/f0dbcd4005dfd4bdfb2b2c0a481ac37b to your computer and use it in GitHub Desktop.
Find Missing Tropy Photos
This file contains 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 | |
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