This repository has been archived by the owner on Jun 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
subotage.sh.in
337 lines (284 loc) · 10.4 KB
/
subotage.sh.in
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
#!/bin/bash
# force indendation settings
# vim: ts=4 shiftwidth=4 expandtab
########################################################################
########################################################################
########################################################################
# Copyright (C) 2017 Tomasz Wisniewski aka
# DAGON <[email protected]>
#
# http://github.com/dagon666
# http://pcarduino.blogspot.co.uk
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
########################################################################
########################################################################
########################################################################
export G_NAPIPREFIX="@NAPI_INSTALL_PREFIX@"
if [ -z "$G_NAPIPREFIX" ] ||
[ ! -d "${G_NAPIPREFIX}" ] ||
[ ! -d "${G_NAPIPREFIX}/lib/napi" ]; then
echo $"Skrypt nie zostal poprawnie zainstalowany!"
exit -1
fi
########################################################################
# libraries
. "${G_NAPIPREFIX}/lib/napi/libnapi_argv.sh"
. "${G_NAPIPREFIX}/lib/napi/libnapi_assoc.sh"
. "${G_NAPIPREFIX}/lib/napi/libnapi_constants.sh"
. "${G_NAPIPREFIX}/lib/napi/libnapi_fs.sh"
. "${G_NAPIPREFIX}/lib/napi/libnapi_logging.sh"
. "${G_NAPIPREFIX}/lib/napi/libnapi_retvals.sh"
. "${G_NAPIPREFIX}/lib/napi/libnapi_subotage.sh"
. "${G_NAPIPREFIX}/lib/napi/libnapi_subs.sh"
. "${G_NAPIPREFIX}/lib/napi/libnapi_tools.sh"
. "${G_NAPIPREFIX}/lib/napi/libnapi_version.sh"
. "${G_NAPIPREFIX}/lib/napi/libnapi_wrappers.sh"
########################################################################
# globals
declare -r ___g_subotageIOFPath=0
declare -r ___g_subotageIOFFormat=1
declare -r ___g_subotageIOFFps=2
declare -r ___g_subotageIOFDetails=3
#
# input file details
# 0 - file path
# 1 - format
# 2 - fps
# 3 - format specific details
#
declare -a ___g_subotageIF=( 'none' 'none' '0' '' )
#
# output file details
# 0 - file path
# 1 - format
# 2 - fps
# 3 - format specific details
#
declare -a ___g_subotageOF=( 'none' 'subrip' '0' '1 0' )
#
# if set to one, print output format summary on exit
#
___g_subotageGetInfo=0
########################################################################
#
# @brief prints the help & options overview
#
_usage() {
local defaultFps=$(subotage_getDefaultFps_SO)
local lastingTime=$(subotage_getLastingTime_SO)
echo "subotage.sh -i <input_file> -o <output_file> [opcje]"
echo "napi bundle version [$g_revision]"
echo
echo "Opcje:"
echo "============="
echo " -i | --input <input_file> - plik wejsciowy (wymagany)"
echo
echo " -o | --output <output_file> - plik wyjsciowy (wymagany)"
echo
echo " -if | --input-format <format> - wymus podany format pliku wejsciowego,"
echo " domyslnie, zostanie wykryty autom."
echo
echo " -of | --output-format <format> - format wyjsciowy (domyslnie subrip)"
echo
echo " -fi | --fps-input <fps> - fps dla pliku wejsciowego (wazne tylko dla formatu microdvd)"
echo " (domyslnie: $defaultFps fps)"
echo
echo " -fo | --fps-output <fps> - fps dla pliku wyjsciowego (wazne tylko dla formatu microdvd)"
echo " (domyslnie: $defaultFps fps)"
echo
echo " -l | --lasting-time <time in ms> - czas wyswietlania linii napisow w milisekundach"
echo " (domyslnie: $lastingTime ms)"
echo
echo " -gi | --get-info <input_file> - wyswietl informacje o pliku wejsciowym i zakoncz"
echo
echo " -gf | --get-formats - wyswietl obslugiwane formaty i wyjdz"
echo
echo " -gl | --get-formats-long - wyswietl obslugiwane formaty (wraz z opisem) i wyjdz"
echo
echo " -v | --verbosity <0..3> - poziom gadatliwosci 0 - cichy, 3 - najgadatliwszy"
echo
echo "Supported formats:"
# list formats
subotage_listFormats 1
}
_subotage_globalArgvDispatcher() {
case "$1" in
"-i" | "--input")
___g_argvOutputHandlerType="variable"
___g_argvOutputHandler="___g_subotageIF[$___g_subotageIOFPath]"
___g_argvErrorMsg=$"nie określono pliku wejsciowego"
;;
"-o" | "--output")
___g_argvOutputHandlerType="variable"
___g_argvOutputHandler="___g_subotageOF[$___g_subotageIOFPath]"
___g_argvErrorMsg=$"nie określono pliku wyjsciowego"
;;
# input format
"-if" | "--input-format")
___g_argvOutputHandlerType="variable"
___g_argvOutputHandler="___g_subotageIF[$___g_subotageIOFFormat]"
___g_argvErrorMsg=$"nie określono formatu wejsciowego"
;;
# output format
"-of" | "--output-format")
___g_argvOutputHandlerType="variable"
___g_argvOutputHandler="___g_subotageOF[$___g_subotageIOFFormat]"
___g_argvErrorMsg=$"nie określono formatu wyjsciowego"
;;
# fps for input file
"-fi" | "--fps-input")
___g_argvOutputHandlerType="variable"
___g_argvOutputHandler="___g_subotageIF[$___g_subotageIOFFps]"
___g_argvErrorMsg=$"nie określono fps pliku wejsciowego"
;;
# fps for output file
"-fo" | "--fps-output")
___g_argvOutputHandlerType="variable"
___g_argvOutputHandler="___g_subotageOF[$___g_subotageIOFFps]"
___g_argvErrorMsg=$"nie określono fps pliku wyjsciowego"
;;
# lasting time
"-l" | "--lasting-time")
___g_argvOutputHandlerType="func"
___g_argvOutputHandler="subotage_setLastingTime"
___g_argvErrorMsg=$"nie okreslono czasu trwania napisow"
;;
# verbosity
"-v" | "--verbosity")
___g_argvOutputHandlerType="func"
___g_argvOutputHandler="logging_setVerbosity"
___g_argvErrorMsg=$"okresl poziom gadatliwosci (0 - najcichszy, 3 - najbardziej gadatliwy, 4 - insane)"
;;
# get formats
"-gl" | "--get-formats-long")
subotage_listFormats 1
return $G_RETBREAK
;;
# get formats
"-gf" | "--get-formats")
subotage_listFormats
return $G_RETBREAK
;;
# get input info
"-gi" | "--get-info")
___g_subotageGetInfo=1
;;
# sanity check for unknown parameters
*)
logging_error $"nieznany parametr:" "[$1]"
return $G_RETPARAM
;;
esac
}
#
# @brief verify the collected user input
#
_verify_argv() {
# check input file path
logging_debug $"sprawdzam plik wejsciowy"
[ -z "${___g_subotageIF[$___g_subotageIOFPath]}" ] || \
[ "${___g_subotageIF[$___g_subotageIOFPath]}" = "none" ] || \
[ ! -s "${___g_subotageIF[$___g_subotageIOFPath]}" ] && {
logging_error $"plik wejsciowy niepoprawny"
return $G_RETPARAM
}
# check presence of output file
logging_debug $"sprawdzam plik wyjsciowy"
[ -z "${___g_subotageOF[$___g_subotageIOFPath]}" ] ||
[ "${___g_subotageOF[$___g_subotageIOFPath]}" = "none" ] &&
[ "$___g_subotageGetInfo" -eq 0 ] && {
logging_error $"nie okreslono pliku wyjsciowego"
return $G_RETPARAM
}
# verifying input format
if [ "${___g_subotageIF[$___g_subotageIOFFormat]}" != "none" ]; then
logging_debug $LINENO $"weryfikuje format wejsciowy"
subotage_isFormatSupported \
"${___g_subotageIF[$___g_subotageIOFFormat]}" ||
return $G_RETPARAM
fi
# verifying output format
logging_debug $LINENO $"weryfikuje format wyjsciowy"
subotage_isFormatSupported \
"${___g_subotageOF[$___g_subotageIOFFormat]}" ||
return $G_RETPARAM
# verify input fps
logging_debug $LINENO $"weryfikuje fps wejsciowy"
subotage_isFpsValidValue "${___g_subotageIF[$___g_subotageIOFFps]}" ||
return $G_RETPARAM
# verify output fps
logging_debug $LINENO $"weryfikuje fps wyjsciowy"
subotage_isFpsValidValue "${___g_subotageOF[$___g_subotageIOFFps]}" ||
return $G_RETPARAM
___g_subotageIF[$___g_subotageIOFFormat]=$(\
echo "${___g_subotageIF[$___g_subotageIOFFormat]}" | \
wrappers_lcase_SO)
___g_subotageOF[$___g_subotageIOFFormat]=$(\
echo "${___g_subotageOF[$___g_subotageIOFFormat]}" | \
wrappers_lcase_SO)
return $G_RETOK
}
#
# @brief parse the cli arguments
#
_parseArgv_GV() {
logging_debug $LINENO $"parsuje opcje globalne"
argv_argvParser_GV _subotage_globalArgvDispatcher "$@" &&
_verify_argv
}
#
# @brief main function
#
_main() {
# if no arguments are given, then print help and exit
# shellcheck disable=SC2086
[ $# -lt 1 ] || [ "$1" = "--help" ] || [ "$1" = "-h" ] && {
_usage
return $G_RETOK
}
logging_msg $"wywolano o" "$(date)"
# verify tools presence
logging_debug $LINENO $"sprawdzam narzedzia ..."
tools_configure_GV || {
logging_error $"nie wszystkie wymagane narzedzia sa dostepne"
logging_debug $LINENO $(tools_toString_SO)
# shellcheck disable=SC2086
return $G_RETFAIL
}
logging_debug $LINENO $(tools_toString_SO)
# configure the rest of libraries
fs_configure_GV
subotage_configure_GV
# parse global arguments
_parseArgv_GV "$@" || {
logging_error $"blad podczas parsowania argumentow"
return $G_RETFAIL
}
# process file
subotage_processFile \
"${___g_subotageIF[@]}" \
"${___g_subotageOF[@]}" \
"$___g_subotageGetInfo"
local status="$?"
[ "${status:-0}" -eq "$G_RETBREAK" ] &&
status=$G_RETOK
return "$status"
}
# call the main
[ "${SHUNIT_TESTS:-0}" -eq 0 ] && {
_main "$@"
}
# EOF