mostly improvements, wip
[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 obs-interlude() {
26 p=$(cat /p/obs-ws-pass)
27 if [[ -e /tmp/no-obs-auto-scene-switch ]]; then
28 rm -f /tmp/no-obs-auto-scene-switch
29 if [[ -s /tmp/last-obs-i3-mark ]]; then
30 mark=$(cat /tmp/last-obs-i3-mark)
31 obs-cmd -w obsws://localhost:4455/$p scene switch $mark
32 fi
33 else
34 touch /tmp/no-obs-auto-scene-switch
35 obs-cmd -w obsws://localhost:4455/$p scene switch interlude
36 fi
37
38 }
39
40 ffmpeg-interlude() {
41 f=/tmp/iank-ffmpeg-interlude-toggle
42
43 # interlude off
44 if [[ -e $f ]]; then
45
46 rm -f $f
47 # note: get _6 from looking for "parsed" ffmpeg debug output.
48 zsend -b tcp://127.0.0.1:5557 Parsed_drawbox_6 t 0
49 zsend -b tcp://127.0.0.1:5557 Parsed_drawtext_7 reinit "text=''"
50
51 else
52
53 # I started an attempt to track if I was muted before an interlude,
54 # but decided against it. Seems easier to handle unmuting with
55 # whatever normal process I have for it.
56 #
57 # muted=$(pactl get-source-mute @DEFAULT_SOURCE@ | awk '{print $2}')
58
59 zsend Parsed_volume_1 volume 0
60 zsend -b tcp://127.0.0.1:5557 Parsed_drawbox_6 t fill
61 zsend -b tcp://127.0.0.1:5557 Parsed_drawtext_7 reinit "text='$(date "+%H\:%M %Z") - Be right back'"
62 touch $f
63 fi
64 }
65
66 zsend() {
67 local out
68 if [[ $1 == -b ]]; then
69 zmq_args=("$1" "$2")
70 shift 2
71 fi
72 out=$(printf "%s\n" "$*" | zmqsend ${zmq_args[@]} ||:)
73 if [[ $out != "0 Success" ]]; then
74 i3-nagbar -m "FAILED zmqsend: $*" -t error -f "pango:monospace 30"
75 fi
76 }
77
78
79 if pgrep '^obs$' &>/dev/null; then
80 obs-interlude
81 else
82 ffmpeg-interlude
83 fi