-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorganise.sh
executable file
·78 lines (72 loc) · 1.58 KB
/
organise.sh
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
#!/bin/bash
usage() {
cat << EOF
usage: $0 options
OPTIONS:
-t the directory files should be moved TO
-f the directory files should be moved FROM
-e the exiftool binary location (defaults to /usr/bin/exiftool)
EOF
}
# http://stackoverflow.com/a/17076258/187954
function abs_path {
(cd "$(dirname '$1')" &>/dev/null && printf "%s/%s" "$PWD" "${1##*/}")
}
TO_DIRECTORY=
FROM_DIRECTORY=
EXIFTOOL_BIN=
while getopts "t:f:" OPTION
do
case $OPTION in
t)
TO_DIRECTORY=$OPTARG
;;
f)
FROM_DIRECTORY=$OPTARG
;;
e)
EXIFTOOL_BIN=$OPTARG
;;
?)
usage
exit
;;
esac
done
if [ -z $TO_DIRECTORY ]; then
usage
exit
fi
if [ -z $FROM_DIRECTORY ]; then
usage
exit
fi
if [ -z $EXIFTOOL_BIN ]; then
EXIFTOOL_BIN=/usr/bin/exiftool
fi
# Verify arguments are directories, symlinks not allowed
FROM_DIRECTORY=$(abs_path $FROM_DIRECTORY)
if [[ ! -d "$FROM_DIRECTORY" || -L "$FROM_DIRECTORY" ]]; then
echo "Invalid path (bad path or it is a symlink):"
echo "$FROM_DIRECTORY"
exit
fi
TO_DIRECTORY=$(abs_path $TO_DIRECTORY)
if [[ ! -d "$TO_DIRECTORY" || -L "$TO_DIRECTORY" ]]; then
echo "Invalid path (bad path or it is a symlink):"
echo "$TO_DIRECTORY"
exit
fi
$EXIFTOOL_BIN -r \
-ext+ AVI -ext+ avi \
-ext+ FLV -ext+ flv \
-ext+ mpeg -ext+ mpeg \
-ext+ MPG -ext+ mpg \
-d "$TO_DIRECTORY/%Y/%m/%d/%Y-%m-%d_%H-%M-%S%%c.%%e" \
"-filename<datetimeoriginal" \
"-filename<CreateDate" \
"-filename<MediaCreateDate" \
"-filename<FileCreateDate" \
"-filename<ModifyDate" \
"-filename<FileModifyDate" \
"$FROM_DIRECTORY"