~carloabelli/bin

bin/import-photos -rwxr-xr-x 1.1 KiB
2c82710aCarlo Abelli Add license 7 months 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
36
37
38
39
40
41
#!/bin/bash

read -p "Empty photos trash [any key to continue]"
while true; do
    if idevicepair pair; then
        break
    fi
    read -p "[any key to continue]"
done
mnt="$(mktemp -d)"
ifuse "$mnt"

pictures="$(xdg-user-dir PICTURES)"
declare -a imported
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 -n "falling back to file modification date!..."
        date="$(stat -c %y "$file" | cut -d ' ' -f 1 | tr - /)"
    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"