-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmerge-generator.sh
95 lines (77 loc) · 2.7 KB
/
merge-generator.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
# an array for the arguments
declare -a args
declare -a audio
declare -a subs
rm -f merge.bat
# color codes
sh_b="\e[1;34m" # blue, welcome text
sh_g="\e[1;32m" # green, success text
sh_c="\e[1;36m" # cyan, info text
sh_r="\e[0m" # reset color
echo -e "${sh_b} Loading merge script generator ${sh_r}"
# loop over all MP4 files
echo -e "${sh_c} INFO ${sh_r} Looking for all mkv files present in the root folder"
for mkv in *.mkv ; do
base="${mkv%mkv}"
args=(--default-language en -o "\"output/${base}mkv\"" "\"${mkv}\"")
subs=()
audio=()
# look for subtitles with the same base name
echo -e "${sh_c} INFO ${sh_r} Looking for subtitles with the same base name"
for subsFile in *.{ass,srt,mks} ; do
subsFileBase=$(grep -F "${base}" <<<"$subsFile")
if [ -e "${subsFileBase}" ]; then
subs=("${subs[@]}" "\"${subsFileBase}\"")
break
fi
done
# look for audio with the same base name
echo -e "${sh_c} INFO ${sh_r} Looking for audio with the same base name"
for subsFile in *.mka ; do
audFileBase=$(grep -F "${base}" <<<"$subsFile")
if [ -e "${audFileBase}" ]; then
audio=("${subs[@]}" "\"${audFileBase}\"")
break
fi
done
# look for eng folder
echo -e "${sh_c} INFO ${sh_r} Checking if 'eng' folder is present"
if [[ -d "eng" ]]; then
echo -e "${sh_c} INFO ${sh_r} 'eng' folder is present"
# look for eng audio with same base name
echo -e "${sh_c} INFO ${sh_r} Looking for audio with the same base name"
for engfile in eng/*.mka ; do
engFileBase=$(grep -F "${base}" <<<"$engfile")
if [ -e "${engFileBase}" ]; then
audio=("${audio[@]}" "\"${engFileBase}\"")
break
fi
done
# look for eng subtitles with same base name
echo -e "${sh_c} INFO ${sh_r} Looking for other subtitles with the same base name in 'eng' folder"
for engfile in eng/*.ass ; do
engFileBase=$(grep -F "${base}" <<<"$engfile")
if [ -e "${engFileBase}" ]; then
subs=("${subs[@]}" "\"${engFileBase}\"")
break
fi
done
fi
args=("${args[@]}" "${audio[@]}" "${subs[@]}")
# look for fonts folder
echo -e "${sh_c} INFO ${sh_r} Looking for 'fonts' folder"
if [[ -d "fonts" ]]; then
for font in fonts/*.ttf ; do
args=("${args[@]}" "--attachment-mime-type application/x-truetype-font --attach-file \"${font}\"")
done
for font in fonts/*.otf ; do
args=("${args[@]}" "--attachment-mime-type application/vnd.ms-opentype --attach-file \"${font}\"")
done
fi
# create output file
echo -e "${sh_c} INFO ${sh_r} Appending to the output file"
echo -e mkvmerge "${args[@]}" >> merge.bat
done
echo -e "${sh_g} SUCCESS ${sh_r} Finished creating output file"
sleep 2