~carloabelli/bin

ref: ba90b29f0668b0480bdf82a0094f6758cb98486e bin/import-photos -rwxr-xr-x 944 bytes
ba90b29fCarlo Abelli Create btrfs snapshot after backup 1 year, 24 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash

idevicepair pair
sleep 30
idevicepair pair || exit 1
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
    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
    fi
    dir="$pictures/$date"
    mkdir -p "$dir"
    new="$dir/$name"
    if [ -f "$new" ]; then
        echo "already exists!"
        break
    fi
    cp "$file" "$new"
    imported+=("$new")
    echo "done"
done
exiftool -all= -overwrite_original ${imported[*]}

umount "$mnt"
rmdir "$mnt"