~carloabelli/bin

4d4214f7fce926d05a890dc06cfc99ebe6379970 — Carlo Abelli a month ago ba90b29
Improve import-photos

- Reminder to empty trash
- Loop until successful pair
- Import from all DCIM folders
- Use file modification date as fallback
1 files changed, 10 insertions(+), 6 deletions(-)

M import-photos
M import-photos => import-photos +10 -6
@@ 1,22 1,26 @@
#!/bin/bash

idevicepair pair
sleep 30
idevicepair pair || exit 1
read -p "Empty photos trash [any key to continue]"
while :; do
    if idevicepair pair; then
        break
    fi
    sleep 10
done
mnt="$(mktemp -d -p $HOME)"
ifuse "$mnt"

pictures="$(xdg-user-dir PICTURES)"
declare -a imported
for file in $(find "$mnt/DCIM/100APPLE" -type f | sort -r); do
for file in $(find "$mnt/DCIM" -type f | sort -r); do
    name="$(basename "$file" | sed -r "s/([^.]*)\$/\L\1/")"
    echo -n "Importing $name..."
    date="$(exiftool -DateTime -S "$file" | cut -d ' ' -f 2 | tr : /)"
    [ -z "$date" ] && date="$(exiftool -DateTimeOriginal -S "$file" | cut -d ' ' -f 2 | tr : /)"
    [ -z "$date" ] && date="$(exiftool -CreateDate -S "$file" | cut -d ' ' -f 2 | tr : /)"
    if [ -z "$date" ]; then
        echo "failed!"
        continue
        echo -n "falling back to file modification date!..."
        date="$(stat -c %y "$file" | cut -d ' ' -f 1 | tr - /)"
    fi
    dir="$pictures/$date"
    mkdir -p "$dir"