-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathultimateCompressor.sh
More file actions
executable file
·111 lines (92 loc) · 3.15 KB
/
Copy pathultimateCompressor.sh
File metadata and controls
executable file
·111 lines (92 loc) · 3.15 KB
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
#!/bin/bash
# Set defaults for the input
input_dir="./";
output_dir="./";
quallity=40;
verbose="0";
# Colors
COLOR_RED='\033[0;31m'
COLOR_GREEN='\033[0;32m'
COLOR_BLUE='\033[0;34m'
COLOR_YELLOW='\033[1;33m'
spinner() {
local i sp n
sp='/-\|'
n=${#sp}
printf ' '
while sleep 0.1; do
printf "%s\b" "${sp:i++%n:1}"
done
}
# Parse the input
while getopts 'i:o:q:v' flag; do
case "${flag}" in
i) input_dir="${OPTARG}" ;;
o) output_dir="${OPTARG}" ;;
q) quallity="${OPTARG}" ;;
v) v="1" ;;
*) print_usage
exit 1 ;;
esac
done
# Parsing
output_dir=$(readlink -f $output_dir);
# Error checking
if [ ! -d $input_dir ]; then
printf "${COLOR_RED}Input directory missing,Stopping process...\n";
exit;
fi
# Tell the user we are reading files
echo "Reading files from $input_dir and exporting to $output_dir";
spinner &
# Check for the output directory, see if you can
if [ ! -d $output_dir ]; then
printf "\n${COLOR_RED}Output directory missing, creating...";
mkdir -p "$output_dir";
fi
# These 3 for loops need to be replaced with a function,
# I have no clue how to do that, and/or how to optimize.
files=$(ls "$input_dir" | grep "[jJ][pP][gG]";);
printf "\n${COLOR_BLUE}Processing JPG files...${COLOR_GREEN}";
for filename in $files; do
filename=$(basename "$filename");
nohup cwebp "$(readlink -f $input_dir)"/"$filename" -q "$quallity" -o "$output_dir"/"$filename".webp > /dev/null 2>&1;
if [ "$v" == "1" ]; then
printf "\n${COLOR_GREEN}Succesfully converted $filename";
fi
done
printf "\n${COLOR_BLUE}Processing PNG files...${COLOR_GREEN}";
ls "$input_dir" | grep "[pP][nN][gG]" | while read filename; do
filename=$(basename "$filename");
nohup cwebp "$(readlink -f $input_dir)"/"$filename" -q "$quallity" -o "$output_dir"/"$filename".webp > /dev/null 2>&1;
if [ "$v" == "1" ]; then
printf "${COLOR_GREEN}Succesfully converted $filename\n";
fi
done
printf "\n${COLOR_BLUE}Processing PNG files...${COLOR_GREEN}";
ls "$input_dir" | grep "[mM][pP]4" | while read filename; do
filename=$(basename "$filename");
nohup ffmpeg -i "$(readlink -f $input_dir)"/"$filename" "$output_dir"/"$filename".mp4 > /dev/null 2>&1;
if [ "$v" == "1" ]; then
printf "${COLOR_GREEN}Succesfully converted $filename\n";
fi
done
printf "\n${COLOR_BLUE}Processing PNG files...${COLOR_GREEN}";
ls "$input_dir" | grep "[fF][lL][vV]" | while read filename; do
filename=$(basename "$filename");
nohup ffmpeg -i "$(readlink -f $input_dir)"/"$filename" "$output_dir"/"$filename".mp4 > /dev/null 2>&1;
if [ "$v" == "1" ]; then
printf "${COLOR_GREEN}Succesfully converted $filename\n";
fi
done
printf "\n${COLOR_BLUE}Processing PNG files...${COLOR_GREEN}";
ls "$input_dir" | grep "[mM][oO][vV]" | while read filename; do
filename=$(basename "$filename");
nohup ffmpeg -i "$(readlink -f $input_dir)"/"$filename" "$output_dir"/"$filename".mp4 > /dev/null 2>&1;
if [ "$v" == "1" ]; then
printf "${COLOR_GREEN}Succesfully converted $filename\n";
fi
done
kill "$!" # kill the spinner
printf '\n'
printf "\n${COLOR_GREEN}Complete!\n"