-
-
Save dmpop/9c2ad06019256df3ff0a6cecab3f3959 to your computer and use it in GitHub Desktop.
Photo import Bash shell script
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 | |
if [ -z "$(command -v notify-send)" ]; then | |
echo "Please install notify-send." | |
exit 1 | |
fi | |
ext1=$3 | |
ext2=$4 | |
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then | |
notify-send "Please specify the required parameters" -i important | |
exit 1 | |
fi | |
# lsblk | grep 'mmcblk0p1' | cut -d' ' -f13 | |
source_dir="$1" | |
target_dir="$2" | |
if [ ! -f "$source_dir/imported.txt" ]; then | |
touch "$source_dir/imported.txt" | |
fi | |
if [ ! -d "$target_dir" ]; then | |
mkdir -p "$target_dir" | |
fi | |
cd "$source_dir" | |
find . -type f -name "*.$ext1" | xargs -I{} rsync -avh {} --exclude-from "$source_dir/imported.txt" "$target_dir" | |
find . -type f -name "*.$ext1" | xargs -I{} basename {} >> imported.txt | |
if [ ! -z $ext2 ]; then | |
find . -type f -name "*.$ext2" | xargs -I{} rsync -avh {} --exclude-from "$source_dir/imported.txt" "$target_dir" | |
find . -type f -name "*.$ext2" | xargs -I{} basename {} >> imported.txt | |
fi | |
sort "$source_dir/imported.txt" | uniq >> "$source_dir/imported-sorted.txt" | |
mv "$source_dir/imported-sorted.txt" "$source_dir/imported.txt" | |
cd "$target_dir" | |
exiftool -d %Y%m%d-%H%M%S.%%e "-FileName<DateTimeOriginal" . | |
exiftool '-Directory<CreateDate' -d ./%Y-%m-%d -r . | |
notify-send "Import completed." -i info |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I added some commentary / documentation to make it easier to use for newcomers. In addition I made the script suitable for Continuous Shooting (multiple photos per second to select the best one afterwards). Feel free to add it to your own code.