-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompress-several.sh
executable file
·73 lines (59 loc) · 1.2 KB
/
compress-several.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
#!/bin/bash
# -h = help, -d = dry run
usage(){
cat << EOF
usage: $0 options directory
This script compresses large movies with handbrake.sh
OPTIONS:
-h Show this message
-d Perform dry-run, printing the files that would be compressed
-n Number of files to compress (compresses n largest files)
EOF
}
NUMBER=20
DIRECTORY=
DRYRUN=false
while getopts "hdn:" OPTION
do
case $OPTION in
h)
usage
exit 1
;;
d) DRYRUN=true;;
n) NUMBER=$OPTARG;;
*)
usage
exit
;;
esac
done
shift $(($OPTIND - 1))
DIRECTORY=$@
if [ -z "$DIRECTORY" ]; then
echo "No directory specified" >&2
exit
fi
if [ ! -d "$DIRECTORY" ]; then
echo "Unknown directory" >&2
exit
fi
FILES=$(find "$DIRECTORY" \( -iregex '.*mkv$' -o -iregex '.*avi$' -o -iregex '.*mp4$' -o -iregex '.*m4v$' -o -iregex '.*mpg$' \) -prune -o -type f -print0 | xargs -0 du -s | sort -nr | head -n $NUMBER | cut -f2)
compress(){
oIFS="$IFS"
IFS="
"
_files="$@"
if [ $DRYRUN = true ]; then
for f in ${_files[*]}; do
printf "File: %s\n" "$f"
done
else
#echo "$@" | while read file ; do
for f in ${_files[*]}; do
handbrake.sh "$f"
done
fi
IFS=oIFS
}
compress "$FILES"