-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto-mkv-srt-mp4-cronjob
138 lines (109 loc) · 3.72 KB
/
auto-mkv-srt-mp4-cronjob
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
auto detect mkv file, extrack subtitles,
crontab -e
@reboot /usr/sbin/netplan apply
@reboot /usr/bin/ran.sh
@reboot /usr/bin/cronfiles.sh
-----------------------------------------------------------
/usr/bin/cronfiles.sh
#!/bin/bash
inotifywait --monitor -e moved_to -e create /mnt/incoming | while read dir;
do
(/usr/bin/process.sh)
done
-------------------------------------------------
process.sh
#!/bin/bash -x
find /mnt/incoming -regextype posix-egrep -regex '.*\.(avi|m2ts|flv|M2TS|3gp|AVI|MPG|mkv|MKV|ogv|wmv|WMV|mp4|mpg|divx|MPG|mpeg|ogg|ogm)$' -exec /usr/bin/mkv.sh " \;
sleep 3
find /mnt/incoming -regextype posix-egrep -regex '.*\.(avi|m2ts|flv|M2TS|3gp|AVI|MPG|mkv|MKV|ogv|wmv|WMV|mp4|mpg|divx|MPG|mpeg|ogg|ogm)$' -exec ffmpeg -i "{}" -c \;
sleep 3
find /mnt/incoming -regextype posix-egrep -regex '.*\.(avi|m2ts|webvtt|M2TS|vtt|ssa|srt|AVI|MPG|mkv|MKV|ogv|wmv|WMV|mp4|mpg|divx|MPG|mpeg|ogg|ogm)$' -exec mv "{}" \;
sleep 3
find /mnt/downloads -regextype posix-egrep -regex '.*\.(vtt|ssa)$' -exec astisub convert -i "{}" -o "{}.srt" \;
sleep 3
cd /mnt/downloads/ && rm -rf *ssa
---------------------------------------------------
mkv.sh
#!/bin/bash
#
# Version 1
#
# (C) 2016 Daniel Faust <[email protected]>
#
# A BASH script that extracts subtitles from a matroska file.
#
# Requires mkvmerge, mkvextract
#
# Usage:
# chmod +x mkv-extract-subtitles
# ./mkv-extract-subtitles "My File.mkv"
#
# This will create a new file for each subtitle in the current directory.
#
# For batch processing all .mkv files in the current directoy
# copy mkv-extract-subtitles to a directory in your PATH and execute:
#
# find -iname "*.mkv" -exec mkv-extract-subtitles '{}' \;
if [[ "$1" == "" ]] || [[ "$1" == "--help" ]] || [[ "$1" == "-h" ]]; then
echo
echo "Process single file:"
echo "mkv-extract-subtitles file.mkv"
echo
echo "Process multiple files:"
echo "find -iname \"*.mkv\" -exec mkv-extract-subtitles '{}'\;"
echo
exit
fi
hash mkvmerge 2>/dev/null || { echo >&2 "Error: Command mkvmerge not found"; exit 1; }
hash mkvextract 2>/dev/null || { echo >&2 "Error: Command mkvextract not found"; exit 1; }
file_name=$1
IFS='
'
tracks=$(LANG=en_US.utf8 LANGUAGE=en_US.utf8 mkvmerge --identify-verbose "$file_name" | tail --lines=+2)
for track in $tracks; do
track_id=""
[[ "$track" =~ Track\ ID\ ([0-9]+) ]] &&
track_id=${BASH_REMATCH[1]}
[[ "$track" =~ language:([a-z]+) ]] &&
language=${BASH_REMATCH[1]}
[[ "$track" =~ track_name:([^ ]+) ]] &&
track_name=${BASH_REMATCH[1]}
[[ "$track" =~ Track\ ID\ [0-9]+:\ ([a-z]*) ]] &&
track_type=${BASH_REMATCH[1]}
ext=""
if [[ "$track" =~ S_TEXT/UTF8 ]]; then
ext="srt"
elif [[ "$track" =~ S_TEXT/ASS ]]; then
ext="ssa"
elif [[ "$track" =~ S_TEXT/USF ]]; then
ext="usf"
elif [[ "$track" =~ S_VOBSUB ]]; then
ext="sub"
elif [[ "$track" =~ S_HDMV/PGS ]]; then
ext="sup"
fi
if [[ "$track_id" == "" ]]; then
continue
fi
if [[ "$track_type" != "subtitles" ]]; then
continue
fi
name="$track_id"
if [[ "$language" != "" ]]; then
name="$name, $language"
fi
if [[ "$track_name" != "" ]]; then
track_name=${track_name/\//_} # replace '/' with '_'
track_name=${track_name/\\s/\ } # replace '\s' with ' '
track_name=${track_name/\\2/\"} # replace '\2' with '"'
track_name=${track_name/\\c/:} # replace '\c' with ':'
track_name=${track_name/\\h/#} # replace '\h' with '#'
# track_name=${track_name/\\\\/\\} # replace '\\' with '\' doesn't work
name="$name, $track_name"
fi
mkvextract tracks "$file_name" "$track_id:${file_name%.*} [$name].$ext"
done
--------------------------------------------------------------------------------------------------------------------
copy binary into /usr/bin/astisub
chmod +x /usr/bin/astisub
ready to be used, for coverting subtitles