distro specific fixes
[distro-setup] / stream-interlude
1 #!/bin/bash
2 # I, Ian Kelling, follow the GNU license recommendations at
3 # https://www.gnu.org/licenses/license-recommendations.en.html. They
4 # recommend that small programs, < 300 lines, be licensed under the
5 # Apache License 2.0. This file contains or is part of one or more small
6 # programs. If a small program grows beyond 300 lines, I plan to switch
7 # its license to GPL.
8
9 # Copyright 2024 Ian Kelling
10
11 # Licensed under the Apache License, Version 2.0 (the "License");
12 # you may not use this file except in compliance with the License.
13 # You may obtain a copy of the License at
14
15 # http://www.apache.org/licenses/LICENSE-2.0
16
17 # Unless required by applicable law or agreed to in writing, software
18 # distributed under the License is distributed on an "AS IS" BASIS,
19 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 # See the License for the specific language governing permissions and
21 # limitations under the License.
22
23 set -e; . /usr/local/lib/bash-bear; set +e
24
25 shopt -s nullglob
26
27 log() {
28 local off_on f
29 local -a webms
30 off_on=$1
31 webms=(/var/icecast/*.webm)
32 last=$(( ${#webms[@]} -1 ))
33 if (( last >= 0 )); then
34 f=${webms[$last]%.webm}.log
35 else
36 f=/var/icecast/interlude.log
37 fi
38 echo $off_on $EPOCHSECONDS >>$f
39 }
40
41 obs-interlude() {
42 p=$(cat /p/obs-ws-pass)
43 if [[ -e /tmp/no-obs-auto-scene-switch ]]; then
44 rm -f /tmp/no-obs-auto-scene-switch
45 if [[ -s /tmp/last-obs-i3-mark ]]; then
46 mark=$(cat /tmp/last-obs-i3-mark)
47 obs-cmd -w obsws://localhost:4455/$p scene switch $mark
48 fi
49 else
50 touch /tmp/no-obs-auto-scene-switch
51 obs-cmd -w obsws://localhost:4455/$p scene switch interlude
52 fi
53
54 }
55
56 ffmpeg-interlude() {
57 f=/tmp/iank-ffmpeg-interlude-toggle
58
59 # interlude off
60 if [[ -e $f ]]; then
61
62 rm -f $f
63 # note: get _6 from looking for "parsed" ffmpeg debug output.
64 zsend -b tcp://127.0.0.1:5557 Parsed_drawbox_6 t 0
65 zsend -b tcp://127.0.0.1:5557 Parsed_drawtext_7 reinit "text=''"
66 log off
67 else
68
69 # I started an attempt to track if I was muted before an interlude,
70 # but decided against it. Seems easier to handle unmuting with
71 # whatever normal process I have for it.
72 #
73 # muted=$(pactl get-source-mute @DEFAULT_SOURCE@ | awk '{print $2}')
74
75 zsend Parsed_volume_1 volume 0
76 zsend -b tcp://127.0.0.1:5557 Parsed_drawbox_6 t fill
77 zsend -b tcp://127.0.0.1:5557 Parsed_drawtext_7 reinit "text='$(date "+%H\:%M %Z") - Be right back'"
78 touch $f
79 log on
80 fi
81 }
82
83 zsend() {
84 local out
85 if [[ $1 == -b ]]; then
86 zmq_args=("$1" "$2")
87 shift 2
88 fi
89 out=$(printf "%s\n" "$*" | zmqsend ${zmq_args[@]} ||:)
90 if [[ $out != "0 Success" ]]; then
91 i3-nagbar -m "FAILED zmqsend: $*" -t error -f "pango:monospace 30"
92 fi
93 }
94
95
96 ffmpeg-interlude
97
98 # obs disabled
99 # if pgrep '^obs$' &>/dev/null; then
100 # obs-interlude
101 # else
102 # ffmpeg-interlude
103 # fi