-
Notifications
You must be signed in to change notification settings - Fork 0
/
smallify-all
executable file
·125 lines (114 loc) · 3.9 KB
/
smallify-all
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
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash
#v1.0
REPLACE=1 # 1 is False
SKIP=1 # 1 is False
SKIPSIZE=0
QUALITY=70
HEIGHT=1920
FOLDER="Smaller_comics"
usage="$(cat <<-EOF
Example :
$(basename "$0")
By default, it saves smallified comics in 'Smaller_comics' default folder.
$(basename "$0") -r or $(basename "$0") --replace
will REPLACE your comics ! Be careful !!
$(basename "$0") -f \"my smaller comics\"
will save your smallified comics in \"my smaller comics\"
$(basename "$0") [-h] [-r] [-f folder]
where:
-h show this help text
-r, --replace set the 'Replace' flag on ! It replace your comics !
Be very careful with this
-f, --folder set the folder where to save smallified comics
-q, --quality set the jpeg quality (0 to 100, default is 70)
-s, --size set the new image height (default is 1920)
-k, --skip skip files if under size (in Mo)
EOF
)"
while :; do
case $1 in
-h|-\?|--help)
#show_help # Display a usage synopsis.
echo "$usage"
exit
;;
-q|--quality) # Takes an option argument; ensure it has been specified.
if [ "$2" ]; then
QUALITY="$2"
# echo "Jpeg quality : '$QUALITY'"
shift
else
die 'ERROR: "--quality" requires a non-empty option argument.'
fi
;;
-s|--size) # Takes an option argument; ensure it has been specified.
if [ "$2" ]; then
HEIGHT="$2"
# echo "Image new height : '$HEIGHT'"
shift
else
die 'ERROR: "--height" requires a non-empty option argument.'
fi
;;
-r|--replace)
REPLACE=0
;;
-k|--skip) # Takes an option argument; ensure it has been specified.
SKIP=0
if [ "$2" ]; then
SKIPSIZE="$2"
# echo "Image new height : '$HEIGHT'"
shift
else
die 'ERROR: "--skip" requires a non-empty option argument.'
fi
;;
-f|--folder) # Takes an option argument; ensure it has been specified.
if [ "$2" ]; then
FOLDER="$2"
# echo "Destination folder : '$FOLDER'"
shift
else
die 'ERROR: "--folder" requires a non-empty option argument.'
fi
;;
--) # End of all options.
shift
break
;;
-?*)
printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
;;
*) # Default case: No more options, so break out of the loop.
break
esac
shift
done
echo "***launching smallify-all in $PWD"
echo "***smallify-all launched with quality $QUALITY and size $HEIGHT. Replace flag is $REPLACE and folder is $FOLDER*******"
for FILE in *{.cbr,.CBR,.cbz,.CBZ}
do
# echo "smallify $FILE 70 1920 $params"
# second argument is jpeg quality
# third argument is the new height of pictures
[ -e "$FILE" ] || continue
# skip ?
FILESIZE=$(du -m "$FILE" | cut -f1)
if [[ $SKIP -eq 0 && "$FILESIZE" -lt "$SKIPSIZE" ]]; then
echo "$FILE is too small -> skipping"
continue
# Stupid mode, because folder is finally deleted in replace mode
elif [[ $REPLACE -eq 0 && ! -z "$FOLDER" ]]; then
smallify "$FILE" "$QUALITY" "$HEIGHT" -r -f "$FOLDER"
# Replace mode, -r option
elif [[ $REPLACE -eq 0 ]]; then
smallify "$FILE" "$QUALITY" "$HEIGHT" -r
# No Replace mode, with custom folder
elif [ ! -z "$FOLDER" ]; then
smallify "$FILE" "$QUALITY" "$HEIGHT" -f "$FOLDER"
# Default mode, no replace
else
smallify "$FILE" "$QUALITY" "$HEIGHT"
fi
echo "====================================================================="
done