-
Notifications
You must be signed in to change notification settings - Fork 0
/
merger.sh
103 lines (85 loc) · 3.09 KB
/
merger.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
96
97
98
99
100
101
102
103
#!/bin/bash
# an array for the arguments
declare -a args
declare -a audio
declare -a subs
declare -a fonts
# 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,MKV} ; do
if [ -e "${mkv}" ]; then
base="${mkv%mkv}"
args=(--default-language en -o "output/${base}mkv" "${mkv}")
subs=()
audio=()
fonts=()
# 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,ASS,srt,SRT,mks,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 audioFile in *.{mka,MKA} ; do
audFileBase=$(grep -F "${base}" <<<"$audioFile")
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,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,ASS} ; do
engFileBase=$(grep -F "${base}" <<<"$engfile")
if [ -e "${engFileBase}" ]; then
subs=("${subs[@]}" "${engFileBase}")
break
fi
done
fi
# look for fonts folder
echo -e "${sh_c} INFO ${sh_r} Looking for 'fonts' folder"
if [[ -d "fonts" ]]; then
for font in fonts/*.{ttf,TTF} ; do
if [ -e "${font}" ]; then
fonts=("${fonts[@]}" --attachment-mime-type application/x-truetype-font --attach-file "${font}")
fi
done
for font in fonts/*.{otf,OTF} ; do
if [ -e "${font}" ]; then
fonts=("${fonts[@]}" --attachment-mime-type application/vnd.ms-opentype --attach-file "${font}")
fi
done
fi
args=("${args[@]}" "${audio[@]}" "${subs[@]}" "${fonts[@]}")
# create output file
echo -e "${sh_c} INFO ${sh_r} Generating output file for ${base}"
mkvmerge "${args[@]}" | (sed -n /^The/q;cat)
# mkvmerge "${args[@]}" | (sed -n /^The/q;cat) | (sed 2d;cat)
fi
done
echo -e "${sh_g} SUCCESS ${sh_r} Finished creating output files"
read -p "Press any key to continue... " -n1 -s