-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert-loop.sh
More file actions
39 lines (32 loc) · 1.12 KB
/
convert-loop.sh
File metadata and controls
39 lines (32 loc) · 1.12 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
#!/bin/bash
#Put source directory here
Source=[Path to Source Directory]
#Destination directory here
Destination=[Path to Destination Directory]
#Handbrake options for encoding
OPTIONS=[Handbrake encoding options]
function convert {
if [ `find "$1" -maxdepth 1 -type f | wc -l` -gt 0 ]; then
repl=`basename "$Source"`
for file in $1/*.mkv ; do
parent=`echo "$1" | sed -e "s/$repl/$Destination/"`
if [ ! -d "$parent" ]; then
mkdir -p "$parent"
fi
OUTPUT="$parent"/"$(basename "$file")"
if [ ! -f "$OUTPUT" ]; then
HandBrakeCLI -i "$file" -o "$OUTPUT" $OPTIONS
fi
done
fi
}
function loop {
for folder in `find "$1" -maxdepth 1 ! -path "$1" -type d` ; do
convert "$folder"
if [ `find "$1" -maxdepth 1 -type d | wc -l` -gt 1 ]
then
loop "$folder"
fi
done
}
loop "$Source"