-
Notifications
You must be signed in to change notification settings - Fork 0
/
getPics
executable file
·114 lines (90 loc) · 2.33 KB
/
getPics
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash
# Add support for NEF files - just duplicate alongside any JPGs
shopt -s nullglob
shopt -s nocaseglob
declare -A destinations
die ()
{
echo "$@"
exit 1
}
checkPrograms ()
{
type exiv2 >/dev/null || die "Can not find 'exiv2'"
type file >/dev/null || die "Can not find 'file'"
}
checkArgs ()
{
from="${1:-$HOME/usb/DCIM/102NCD40}"
to="${2:-$HOME/PicsToSort}"
to="${to%/}"
num="${from##*/1?}"
num="${num%/}"
num="${num%NCD?0}"
[[ -d $from ]] || die "$from not a dir"
[[ -d $to ]] || die "$to not a dir"
[[ $num ]] || die "No num extracted from $from"
read -p "Moving from $from to $to, applying number $num. Ctrl-C now to quit." -n1 -t5
}
pictaken ()
{
exiv2 "$1" | sed -n '/Image timestamp/ {s/Image timestamp : //; s/ .*//; s/^....://; s/://; p}'
}
processFolder ()
{
for item ; do
#echo "Processing $item"
if [[ -d $item ]] ; then
item="${item%/}"
die "I do not expect a directory here - $item"
elif [[ -f $item ]] ; then
fnam="${item##*/}"
filenamebase="${fnam%.*}"
# Check file type
mime=$(file -bi "$item")
[[ $mime = image/jpeg* ]] || { echo "$item is not a jpeg image" ; continue ; }
# Get image date
pt="$(pictaken "$item")"
[[ $pt ]] || { echo "Failed to get date for $item" ; continue ; }
pt="${to}/${pt}"
destinations["$pt"]=1
[[ ! -d $pt ]] && { mkdir "$pt" || die "Failed to create directory $pt" ; }
[[ -e $pt/$fnam ]] && { echo "$fnam already exists in $pt" ; continue ; }
mv -f "$item" "$pt/${fnam/_/_$num}" 2>/dev/null || {
echo "Failed to mv $item to $pt" ; continue ;
}
[[ -f "${item%.*}.NEF" ]] && mv -f "${item%.*}.NEF" "$pt/${filenamebase/_/_$num}.NEF" 2>/dev/null
fi
done
}
initDestinations ()
{
#printf "Dirs to process: " ; printf "%s, " "$@" ; printf "\n";
#return
for dir ; do
mkdir "$dir/bu"
mv "$dir/"*.{JPG,JPEG} "$dir/bu"
shopt -s nullglob
nefs=("$dir/"*.NEF)
if [[ ${#nefs[@]} ]] ; then
mkdir "$dir/raw"
mv "$dir/"*.NEF "$dir/raw"
fi
mkdir "$dir/small" || die "Failed to make dir"
(
cd "$dir/bu"
exiftran -ai *
all=(*)
for i in * ; do
convert -resize 35%x35% "$i" ../small/"$i"
printf "\r%d%%" $(( 100 * ++c / ${#all[@]} ))
done
printf "\n"
printf "%s\n" *.* > ../all.list
)
done
}
checkPrograms
checkArgs "$@"
processFolder "$from/"*
initDestinations "${!destinations[@]}"