-
Notifications
You must be signed in to change notification settings - Fork 0
/
strobs
executable file
·608 lines (556 loc) · 24.7 KB
/
strobs
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
#! /bin/sh
#
# Stream-Observer (strobs) is a script to observe running voc video streams.
#
# The script opens mpv with all active (currently streaming) streams from
# Chaos Computer Club made by VOC (video operation center) in a playlist
# as found at https://streaming.media.ccc.de.
# Optionally it can also try to open all streams given in a valid playlist.
#
# MIT License
# Copyright (c) 2020 Simpel
# SPDX-FileCopyrightText: 2020 Simpel <[email protected]>
#
# SPDX-License-Identifier: MIT
# Shell Strict Mode: http://redsymbol.net/articles/unofficial-bash-strict-mode
# set -e: exit if something fails; set -u: exit if a variable is unset
# set -o pipefail: prevents errors in a pipeline from being masked
# If a command in pipeline fails, return code will be return code of whole pipeline
set -euo pipefail
# word splitting shall happen only on newlines and tab characters
# By default it is set to $' \n\t' - space, newline, tab - which is too eager
IFS=$'\n\t'
#######################################
### Globals
#######################################
readonly streamjsonurl="https://streaming.media.ccc.de/streams/v2.json"
readonly red='\033[0;31m'
readonly yellow='\033[0;33m'
readonly nc='\033[0m' # No Color
readonly underlined='\033[4m'
readonly progname="${0##*/}"
readonly progpath="${0%/*}/"
readonly version="4.0.36"
unset debug # if set print verbose messages red to differ from debug messages
unset exitscript # if set don't open mpv; useful for debugging and json export
unset force # if set and used with option -p / -j forces open playlist / load full json
unset JSON # if set contains the whole streaming json content
unset print_json # if set export json to disk
unset playlist # if set use directly this playlist
unset playlist_info # if set contains Info line in mvp what stream it is
unset sort # if set servers sorted alphanumerical else as found
unset timetable # if set timetable of running and coming events is printed
verbosity=0 # if > 0 show verbose messages in levels
#######################################
### Functions
#######################################
#######################################
# Print verbose messages (in red if debug).
# Globals:
# verbosity
# debug
# red
# nc
# Arguments:
# level
# Outputs:
# msg to STDERR
# Returns:
# None
#######################################
verbose() {
msg="${1}"
level="${2:-1}" # default 1 if not given
i=0
# only level up to verbosity
if [ ${level} -le ${verbosity} ]; then
# print '=' for every level
while [ ${i} -lt ${level} ]; do
# colorize in debug mode
if [ -n "${debug-}" ]; then
printf "${red}=${nc}\n" >&2
else
printf "=" >&2
fi
i=$((${i} + 1))
done
# print verbose message (colorize in debug mode)
if [ -n "${debug-}" ]; then
echo "${red}> ${msg}${nc}" >&2
else
echo "> ${msg}" >&2
fi
fi
}
#######################################
# Show extracted shortcuts from input.conf.
# Globals:
# progpath
# yellow
# nc
# Arguments:
# None
# Outputs:
# shortcut to STDOUT
# Returns:
# None
#######################################
keys() {
if [ ! -f "${progpath}input.conf" ]; then
printf "%b\n" "${yellow}Warning: '${progpath}input.conf' with key definition does not exist${nc}" 1>&2
exit 1
fi
echo "Shortcuts:"
# grep all lines start not with #
grep '^[[:blank:]]*[^[:blank:]#]' ${progpath}input.conf
verbose "keys (${LINENO}): grep shortcuts from 'input.conf': $?" 2
exit 0
}
#######################################
# Prints timetable with conferene, start and end date.
# Globals:
# None
# Arguments:
# api json in JSON
# Outputs:
# startsAt \t endsAt \t conferene to STDOUT
# Returns:
# None
#######################################
timetable_array() {
verbose "timetable_array (${LINENO}): Create timetable array"
# Clean json from invalid new lines
result="$(echo "$1" | tr -d '\r\n')"
# Catch conference, startsAt, endsAt of every stream event
result="$(echo "$result" | jq -r '.[]|.startsAt,.endsAt,.conference')"
verbose "timetable_array (${LINENO}): Exctract 'startsAt, endsAt, conference' from json: $?" 2
# Remove +0000 in timestamps
result="$(echo "${result}" | sed 's/+0000//g')"
verbose "timetable_array (${LINENO}): Remove '+0000': $?" 2
# make one event in one line
result="$(echo "${result}" | awk '{if (NR%3) {ORS="\t";print $0} else {ORS="\n";print $0}}')"
# Return only events that are running or planned
date="$(date -u +"%Y-%m-%dT%H:%M:%S")" # now
result="$(echo "${result}" | awk -F '\t' -v force_date="${date}" '$2>=force_date && $2!="null" {print $0}')"
verbose "timetable_array (${LINENO}): Strip timetable array to now"
# Remove disturbing 'T' from UTC timestamps
result="$(echo "${result}" | sed 's/\([0-9]\{4\}-[0-9][0-9]-[0-9][0-9]\)T\([0-9][0-9]:[0-9][0-9]:[0-9][0-9]\)/\1 \2/g')"
verbose "timetable_array (${LINENO}): Remove 'T' from timestamps: $?" 2
if [ -z "${result-}" ]; then
printf "%b\n" "${yellow}Warning: no events found${nc}" 1>&2
else
printf "%b\n" "${yellow}starts at (UTC)\t\tends at (UTC)\t\tconference${nc}" 1>&2
printf "%b\n" "${result}" 1>&2
fi
}
#######################################
# Extract conferences from json.
# Globals:
# None
# Arguments:
# JSON
# Outputs:
# (conference \n conference \n ...)* to STDOUT
# Returns:
# result
#######################################
get_conferences() {
verbose "get_conferences (${LINENO}): Create conferences array"
result="$(echo "$1" | jq -r '.[].conference')"
verbose "get_conferences (${LINENO}): Output 'conferences' with jq: $?" 2
verbose "get_conferences:\n$result" 3
echo "${result}"
}
#######################################
# Extract stream names array from json.
# Globals:
# None
# Arguments:
# JSON
# CONFERENCE
# Outputs:
# (stream name \n stream name \n ...)* to STDOUT
# Returns:
# result
#######################################
get_stream_display_names() {
verbose "get_stream_display_names (${LINENO}): Create stream_display_names array"
result="$(echo "$1" | jq -r '.[]|select(.conference == "'"$2"'").groups[].rooms[].display')"
verbose "get_stream_display_names (${LINENO}): Output 'stream_display_names' with jq: $?" 2
verbose "get_stream_display_names:\n$result" 3
echo "${result}"
}
#######################################
# Extract stream url from json.
# Globals:
# None
# Arguments:
# JSON
# CONFERENCE
# STREAM_NAME
# Outputs:
# url to STDOUT
# Returns:
# result
#######################################
get_stream_url() {
verbose "get_stream_url (${LINENO}): Search in json"
result="$(echo "$1" | jq -r '.[]|select(.conference == "'"$2"'").groups[].rooms[]|select(.display == "'"$3"'").streams[]|select(.slug == "hd-native").urls.hls.url')"
verbose "get_stream_url (${LINENO}): Output 'stream_url' with jq: $?" 2
verbose "get_stream_url:\n$result" 3
echo "${result}"
}
#######################################
# Returning room names sorted alphanumerical.
# Globals:
# None
# Arguments:
# STREAM_NAMES
# Outputs:
# sorted streams to STDOUT
# Returns:
# None
#######################################
sort_alphanum() {
verbose "sort_alphanum (${LINENO}): Sorting room names"
# Padding numbers with zeros to make sort with leading characters work
result="$(echo "$1" | awk '{ gsub(/([^[:digit:]]+|[[:digit:]]+)/,"&\t") ; printf("%s%05d\n", $1, $2)}')"
verbose "sort_alphanum (${LINENO}): Fill numbers with leading zeros: $?" 2
result="$(echo "${result}" | sort -n)"
verbose "sort_alphanum (${LINENO}): Sort numerical: $?" 2
# Split leading characters to remove padded zeros
result="$(echo "${result}" | awk '{ gsub(/([^[:digit:]]+|[[:digit:]]+)/,"&\t") ; print $1, $2}')"
verbose "sort_alphanum (${LINENO}): Split at beginning of number: $?" 2
result="$(echo "${result}" | awk '{gsub ("^0*", "", $2); printf("%s%s\n", $1, $2)}')"
verbose "sort_alphanum (${LINENO}): Strip leading zeros and merge: $?" 2
echo "${result}"
}
#######################################
# Print streaming.json, icecast-status.xsl.
# Globals:
# None
# Arguments:
# None
# Outputs:
# None
# Returns:
# None
#######################################
printjson() {
verbose "printjson (${LINENO}): Print status_liveber.xsl, status_ingest.xsl, current.json"
# Export icecast status to disk
curl -sSf http://live.ber.c3voc.de:7999/status-json.xsl >status_liveber.xsl
curl -sSf http://ingest.c3voc.de:8000/status-json.xsl >status_ingest.xsl
# Export streaming.json to disk
if [ -n "${force-}" ]; then
# with option forceopen=1 (shows all streams done, running and planned)
JSON="$(curl -sSf ${streamjsonurl}?forceopen=1)"
else
# shows only running streams
JSON="$(curl -sSf ${streamjsonurl})"
fi
echo "${JSON}" >current.json
# Don't start mpv and avoid deleting current-playlist.m3u8
exitscript=true
}
#######################################
# Cleanup on exit.
# Delete current-playlist (if not exitscript).
# Globals:
# playlist
# exitscript
# Arguments:
# None
# Outputs:
# None
# Returns:
# None
#######################################
cleanup() {
verbose "cleanup (${LINENO}): Cleanup on exit" 3
# delete current playlist
playlist="${progpath}current-playlist.m3u8"
if [ -e "${playlist}" ] && [ -z "${exitscript-}" ]; then
rm "${playlist}"
verbose "cleanup (${LINENO}): Delete 'current-playlist.m3u8': $?" 3
fi
# delete voctocat.gif
if [ -e "${progpath}voctocat.gif" ] && [ -z "${exitscript-}" ]; then
rm "${progpath}voctocat.gif"
verbose "cleanup (${LINENO}): Delete 'voctocat.gif': $?" 3
fi
exit 0
}
#######################################
# Opens man page strobs.1.
# Globals:
# progpath
# yellow
# nc
# Arguments:
# None
# Outputs:
# None
# Returns:
# None
#######################################
manpage() {
if [ ! -f "${progpath}strobs.1" ]; then
printf "%b\n" "${yellow}Warning: man page '${progpath}strobs.1' does not exist${nc}" 1>&2
exit 1
fi
man ${progpath}strobs.1
exit 0
}
#######################################
# Prints the usage manual.
# Globals:
# progname
# underlined
# nc
# Arguments:
# None
# Outputs:
# usage to SDTOUT
# Returns:
# None
#######################################
manual() {
echo "Usage: ${progname} [ -d | -D | -f | -h | -i | -j | -k | -m | -p ${underlined}file${nc} | -s | -t | -v | -V | -x]"
echo " opens mpv with all active voc streams"
echo " -d debug mode: print commands and arguments while executed"
echo " -D debug mode: print script lines while read"
echo " -f forces (with -p / -j) open playlist / download full json"
echo " -h help shown"
echo " -i ingest streams using"
echo " -j json export to disk"
echo " -k keys/shortcuts shown"
echo " -m man page shown"
echo " -p playlist ${underlined}file${nc} with servers in format m3u8"
echo " -s sort room names alphanumerical"
echo " -t timetable of running and coming events shown"
echo " -v verbosity increasing with ${underlined}v${nc}"
echo " -V version print"
echo " -x exit before mpv, keeps current-playlist.m3u8"
exit 0
}
#######################################
# Creates voctocat.gif.
# Globals:
# progpath
# Arguments:
# None
# Outputs:
# None
# Returns:
# None
#######################################
voctocat_file() {
voctocat="R0lGODdh0gA4BPcAAAAAAAEBAQICAgMDAwQEBAUFBQYGBgcHBwgICAkJCQo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JsqXLlzBjypxJs6bNmzhz6tzJs6fPn0CDCh1KtKjRo0iTKl3KtKnTp1CjSp1KtarVq1izat3KtavXr2DDih1LtqzZs2jTql3Ltq3bt3Djyp1Lt67du3jz6t3Lt6/fv4ADCx5MuLDhw4gTK17MuLHjx5AjS55MubLly5gza97MubPnz6BDix5NurTp06hTq17NurXr17Bjy55Nu7bt27hz697Nu7fv38CDCx9OvLjx48iTK1/OvLnz59CjS59Ovbr169iza9/Ovbv37+DDi/8fT768+fPo06tfz769+/fw48ufT7++/fv48+vfz7+///8ABijggAQWaOCBCCao4IIMNujggxBGKOGEFFZo4YUYZqjhhhx26OGHIIYo4ogklmjiiSimqOKKLLbo4oswxijjjDTWaOONOOao44489ujjj0AGKeSQRBZp5JFIJqnkkkw26eSTUEYp5ZRUVmnllVhmqeWWXHbp5ZdghinmmGSWaeaZaKap5ppstunmm3DGKeecdNZp55145qnnnnz26eefgAYq6KCEFmrooYgmquiijDbq6KOQRirppJRWaumlmGaq6aacdurpp6CGKuqopJZq6qmopqrqqqwu2AALQFD/ccYejVTCiSipvOIKKqFsQskhdIDRhA4hEDAbAjJ8ocgqzLDzz7PQRivttM/uA84vn+jRxAcBnEZADXCgYs0+1JZr7rnPwjNMJFdw8BkBOwjiCz3o1mvvueCUUkYHmGUQhiru3CvwwOX6M80iQhQQ2QVqANMPwRBHPC07mxRhrGIKgMELPxJ37DG06lhSw2EyWALPxyin/IwaDwRWABfMpCyzzPVwskJfD9Axzsw8y+xPLULkNQEi8fRs9MzNPNHtXBAIUvTRUMusDBJxJaBHwFFnLXMxPbh1BThah+1zKh+oNcMwYqctsz2CLGAWA5I8rPbcKIOTBFlKhEP33imX/1IBWBOUwvfgKK+jhVdDkEP44h+bAoFWBiwiN+OURwxO11eR8EzlnEvMTyACVNXEO52XHjEuEkglgCCTm+76vd7EAJUDtrxu+8D2bOFUB9Lc7vu9/vTBlAzl/G68vZ8ojJQS8xzvPLq8OHBUFfo8b725yqROFBgcX+/9tNJcMNQar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+wx/UAKDDwTKOyMav+YFAHQB24rLdo6yOfrjTVhDfVCDYecFFUwl+XSxxw8MM7gyTdxouZSCzq8FDTwftTixmVMMN6gBfPrErA5LY6gxUFxAfZaLiH6yeiyDnDAlDkxAJB0D2RAFQMwCAl0b5J8c4UguzlBY9NiDe9KFUgwsNICRrdbL/uwCWz5EypALZyQxlZxAbMgLahAx+cCC9AYFD4gLfCglVxBBnT1C+hMLcXQqz/hls8SDA/LFSLQWwiWzdNyDTUsFEf4DmUQy1TRBekwbwINLeZgBgUYFDCqCiA8FhKwCQJsxc8SD3zQskfRCAG6F8mYD5JwxLkZGJdwCubnHM7cKjAd0zI90zT/XdM2fdM4ndM6vdM83dM+/dNAHdRCPdREXdRGfdRIndRKvdRM3dRO/dRQHdVSPdVUXdVWfdVYndVavdVc3dVe/dVgHdZiPdZkXdZmfdZondZqvdZs3dZu/dZwHddyPdd0Xdd2fdd4ndd6vdd83dd+/deAHdiCPdiEXdiGfdiIndiKvdiM3diO/diQHdmSPdmUXdmWfdmYndmavdmc3dme/dmgHdqiPdqkXdqmfdqondqqvdqs3dqu/dqwHduyPdu0Xdu2fdu4ndu6vdu83du+/dvAHdzCPdzEXdzGfdzIndzKvdzM3dzO/dzQHd3SPd3UXd3Wfd3Ynd3avd3c3d3eDf3d4B3e4j3e5O0UAQEAOw=="
verbose "voctocat_file (${LINENO}): export voctocat.gif"
echo "${voctocat}" | base64 -D -o "${progpath}voctocat.gif"
verbose "voctocat_file (${LINENO}): base64 voctocat.gif: $?" 2
}
#######################################
### Main
#######################################
# Check options
while getopts 'dDfhijkmp:stvVx' option 2>/dev/null; do
case "${option}" in
d)
set -x # print commands and arguments while executed
debug=true
;;
D)
set -v # print script lines while read
debug=true
;;
f) force=true ;;
h) manual ;;
i) play_ingest=true;;
j) print_json=true ;;
k) keys ;;
m) manpage ;;
p) playlist="${OPTARG}" ;;
s) sort=true ;;
t)
timetable=true
force=true
;;
v) verbosity=$((${verbosity} + 1)) ;;
V)
echo "${progname} version ${version}"
exit 0
;;
x) exitscript=true ;;
*)
if [ $1 != "-?" ]; then
curropt=$((${OPTIND} - 1))
eval "curropt=\$${curropt}"
printf "%b\n" "${yellow}Warning: illegal option ${curropt}${nc}" 1>&2
fi
manual
;;
esac
done
verbose "${yellow}Note: number after colon usually represents commands exit code${nc}"
verbose "Level of verbosity: ${verbosity}"
# Exit handler
trap cleanup 0 1 2 3 6
# Check for option -j
if [ -n "${print_json-}" ]; then
printjson
fi
# Check for option -t; print timetable of running and coming events
if [ -n "${timetable-}" ]; then
# First disable exit on error as this is not important to run
set +e
# with option forceopen=1 (shows all streams done, running and planned)
JSON="$(curl -sSf ${streamjsonurl}?forceopen=1)"
verbose "main (${LINENO}): Curl json for option -t: $?" 2
# Enable exit on error again
set -e
# Check for curl error: if so json is empty
if [ "$(echo "${JSON}")" = "" ]; then
printf "%b\n" "${yellow}Warning: no json for timetable available${nc}" 1>&2
else
# Print start date, end date and conference from $JSON
timetable_array "${JSON}"
fi
exit 0
fi
# Check if mpv is existing
if ! [ -x "$(command -v mpv)" ]; then
printf "%b\n" "${red}Error: mpv does not exist, please install${nc}" 1>&2
printf "%b\n" "Look: https://mpv.io/installation" 1>&2
exit 1
fi
# Check if jq is existing
if ! [ -x "$(command -v jq)" ]; then
printf "%b\n" "${red}Error: jq does not exist, please install${nc}" 1>&2
printf "%b\n" "Look: https://stedolan.github.io/jq" 1>&2
exit 1
fi
# Create voctocat.gif
voctocat_file
# Choose the playlist
# Playlist given with option -p
if [ -n "${playlist-}" ]; then
verbose "Used playlist: ${playlist}"
if [ ! -f "${playlist}" ]; then
if wget --spider "${playlist}" 2>/dev/null; then
verbose "Used playlist is remote"
else
if [ ! -n "${force-}" ]; then
printf "%b\n" "${yellow}Warning: playlist '${playlist}' does not exist, but you can enforce with option -f${nc}" 1>&2
exit 1
fi
fi
fi
else
# Playlist should have only streams found at streaming json
playlist="${progpath}current-playlist.m3u8"
verbose "Used playlist: ${playlist}"
# Catch streams status
# curl -s (silent mode - no progress or error messages)
# -S (show-error - used with -s it shows an error message if it fails)
# -f (fail silently)
# not exiting if curl is failing
set +e
JSON="$(curl -sf ${streamjsonurl})"
set -e
verbose "${JSON}" 4
verbose "main (${LINENO}): Read stream json"
if [ -z "${JSON-}" ]; then
printf "%b\n" "${yellow}Warning: no active streams available${nc}" 1>&2
exit 1
fi
# Clean json from invalid new lines
JSON="$(echo "$JSON" | tr -d '\r\n')"
# Find all running conferences
CONFERENCES="$(get_conferences "${JSON}")"
# Exit if no conference found
if [ "${CONFERENCES}" = "" ]; then
printf "%b\n" "${yellow}Warning: no live conference available${nc}" 1>&2
exit 1
fi
# Create playlist
# Playlist header
echo "#EXTM3U" >"${playlist}"
echo "#EXT-X-VERSION:3" >>"${playlist}"
# Repeat playlist names and servers and "#EXT-X-DISCONTINUITY"
verbose "main (${LINENO}): Create playlist"
counter="1"
for CONFERENCE in ${CONFERENCES}; do
# Find streams in $JSON
STREAM_NAMES="$(get_stream_display_names "${JSON}" "${CONFERENCE}")"
# Exit if no servers found
if [ "${STREAM_NAMES}" = "" ]; then
printf "%b\n" "${yellow}Warning: no live streams available${nc}" 1>&2
exit 1
fi
# Sort stream_display_names alphanumerical
if [ -n "${sort-}" ]; then
STREAM_NAMES="$(sort_alphanum "${STREAM_NAMES}")"
fi
verbose "Extracted stream_display_names:\n${STREAM_NAMES}" 3
for STREAM_NAME in ${STREAM_NAMES}; do
STREAM_URL="$(get_stream_url "${JSON}" "${CONFERENCE}" "${STREAM_NAME}")"
playlist_info=${CONFERENCE}" - "${STREAM_NAME}
# add numbers for direct call in mpv
playlist_info=${playlist_info}" - #"${counter}
# Write stream as info into playlist
echo "#EXTINF:0,${playlist_info}" >>"${playlist}"
verbose "main (${LINENO}): Add ${playlist_info} to playlist: $?" 3
# Write url into playlist
echo "${STREAM_URL}" >>"${playlist}"
verbose "main (${LINENO}): Add ${STREAM_URL} to playlist: $?" 3
# Write playlist divider
echo "#EXT-X-DISCONTINUITY" >>"${playlist}"
counter=$((counter + 1))
done
done
{
# Set a picture as last, so mpv will not end
echo "#EXTINF:0,end of list"
echo "${progpath}voctocat.gif"
# End of playlist
echo "#EXT-X-ENDLIST"
} >>"${playlist}"
verbose "main (${LINENO}): Playlist complete: $?"
fi
# Exit if set option '-x'
if [ -n "${exitscript-}" ]; then
exit 0
fi
# That is really playing
# Check mpv options in README.md
mpv "${playlist}" \
--fs \
--no-ytdl \
--msg-level=all=error,ffmpeg=fatal \
--no-input-default-bindings \
--input-conf=${progpath}input.conf \
--load-scripts=no \
--scripts=${progpath}keys.lua \
--force-window=immediate \
--keep-open=always \
--idle=yes \
--vd-lavc-show-all=yes \
--no-initial-audio-sync \
--audio-stream-silence=yes \
--demuxer-cache-wait=no \
--force-seekable=no \
--image-display-duration=inf \
--screenshot-format=png \
--script-opts=osc-visibility=always,osc-seekbarstyle=knob \
--osd-duration=5000 \
--osd-msg1="room: 1 – 0 audio: q, w, e - Native, Translated, Translated-2 video: y, x - HD, Slides" \
--no-osd-bar \
--osd-font-size=30 \
--osd-spacing=1 \
--osd-border-size=1 \
--osd-margin-x=10 \
--osd-margin-y=4
verbose "Exit"
exit 0