Skip to content

Commit

Permalink
Merge branch 'feature/voctomix-2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Kunsi committed Apr 22, 2024
2 parents 0f26b25 + 9ac1572 commit c1157c2
Show file tree
Hide file tree
Showing 29 changed files with 622 additions and 120 deletions.
6 changes: 3 additions & 3 deletions bundlewrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ the key `overlays` to `yourevent.toml`. The value of this key should be
a full-blown URL pointing to a `.tar.gz`-Archive containing the overlays
themselves. You can create it using `tar -czf overlays.tar.gz *.png`.

If the event uses a `schedule.xml` file, you can add it to the config
using the `schedule_xml` key. This needs to be a URL, too.
If the event uses a `schedule.json` file, you can add it to the config
using the `schedule_json` key. This needs to be a URL, too.

If the event does not use a schedule, you can specify
filename-to-title-Mappings yourself. You can do so using the
Expand All @@ -125,7 +125,7 @@ will take preference.

```toml
[metadata.event]
schedule_xml = "https://example.com/schedule.xml"
schedule_json = "https://example.com/schedule.json"
overlays = "https://example.com/overlays.tar.gz"

[metadata.event.overlay_mappings]
Expand Down
2 changes: 1 addition & 1 deletion bundlewrap/bundles/crs-worker/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'packages': {
'cifs-utils': {},
'ffmpeg': {},
'fuse': {},
'fuse3': {},
'fuse-ts': {},
'libboolean-perl': {},
'libconfig-inifiles-perl': {},
Expand Down
4 changes: 4 additions & 0 deletions bundlewrap/bundles/encoder-common/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
directories[f'/video'] = {
'owner': user_group,
'group': user_group,
'after': {
'zfs_dataset:',
'zfs_pool:',
},
}

for path in (
Expand Down
9 changes: 7 additions & 2 deletions bundlewrap/bundles/loudness-rendering/files/loudness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ then
exit 0
fi

mkdir -p "/opt/loudness-rendering/data/${NAME}"
touch "/opt/loudness-rendering/data/${NAME}/line1.txt"
touch "/opt/loudness-rendering/data/${NAME}/line2.txt"

/usr/local/sbin/voc2alert "info" "loudness" "Loudness monitoring for ${NAME} started ..."

ffmpeg \
Expand All @@ -32,8 +36,9 @@ ffmpeg \
[a1] aformat=sample_fmts=fltp:sample_rates=48000:channel_layouts=stereo [audio];
[base][v1] overlay=shortest=1 [tmp1];
[tmp1][scaled] overlay=shortest=1:y=360 [ov];
[ov] drawtext='fontcolor=white:x=45:y=36:fontsize=60:fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf:text=${ROOM}' [ov1];
[ov1] drawtext='fontcolor=white:x=45:y=101:fontsize=30:fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf:text=${NAME}' [out]" \
[ov] drawtext='fontcolor=white:x=45:y=36:fontsize=50:fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf:textfile=/opt/loudness-rendering/data/${NAME}/line1.txt:reload=30' [ov1];
[ov1] drawtext='fontcolor=white:x=45:y=86:fontsize=20:fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf:textfile=/opt/loudness-rendering/data/${NAME}/line2.txt:reload=30' [ov2];
[ov2] drawtext='fontcolor=white:x=45:y=111:fontsize=20:fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf:text=${ROOM} - ${NAME}' [out]" \
-map "[out]" -c:v libx264 -threads 2 -preset veryfast -x264-params keyint=30 -tune zerolatency -crf:0 26 -profile:0 high -level:0 4.1 -c:a aac -strict -2 -pix_fmt yuv420p \
-map "[audio]" -c:a aac -b:a 128k \
-f flv \
Expand Down
2 changes: 2 additions & 0 deletions bundlewrap/bundles/loudness-rendering/files/service
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ After=network.target

[Service]
Type=simple
User=voc
Group=voc
ExecStart=/usr/local/bin/loudness_rendering "${identifier}" "${source_url}" "${output}" "${room_name}"
Restart=always
RestartSec=10
Expand Down
88 changes: 88 additions & 0 deletions bundlewrap/bundles/loudness-rendering/files/updater.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/usr/bin/env python3

import json
import os
import logging
from sys import exit
from datetime import datetime, timedelta
from zoneinfo import ZoneInfo
from subprocess import run

logging.basicConfig(level=logging.DEBUG)

LOG = logging.getLogger('loudness_info_updater')
BASE_DIR = '/opt/loudness-rendering'
DATA_DIR = f'{BASE_DIR}/data'

try:
with open('/opt/voc/schedule.json') as f:
schedule = json.load(f)
except (FileNotFoundError, json.decoder.JSONDecodeError):
LOG.exception('could not load schedule')
exit(0)

try:
with open(f'{BASE_DIR}/config.json') as f:
config = json.load(f)
except (FileNotFoundError, json.decoder.JSONDecodeError):
LOG.exception('could not load config')
exit(1)

rooms = {v['room']: k for k,v in config['streams'].items()}

TZ = ZoneInfo(schedule['schedule']['conference']['time_zone_name'])
LOG.debug(f'{TZ=}')
NOW = datetime.now(TZ)
LOG.info(f'{NOW=}')

room_info = {stream: None for stream in config['streams']}

for day in schedule['schedule']['conference']['days']:
for room_name, room_talks in day['rooms'].items():
if room_name not in rooms:
LOG.debug(f'ignoring {room_name} because not configured')
continue

for talk in room_talks:
talk['__start'] = datetime.strptime(talk['date'][:19], '%Y-%m-%dT%H:%M:%S').replace(tzinfo=TZ)
d_h, d_m = talk['duration'].split(':')
talk['__end'] = talk['__start'] + timedelta(hours=int(d_h), minutes=int(d_m))

if talk['__start'] <= NOW < talk['__end']:
room_info[rooms[room_name]] = talk
break

for f in os.scandir(DATA_DIR):
if (
not f.name.startswith('.')
and f.name not in room_info
):
LOG.debug(f'deleting {f.name} because not configured')
run(['rm', '-rf', os.path.join(DATA_DIR, f)])

for stream, talk in room_info.items():
os.makedirs(os.path.join(DATA_DIR, stream), exist_ok=True)

line2 = []
if talk:
if talk['do_not_record']:
line2.append('OPTOUT')
line2.append(talk['__start'].strftime('%H:%M'))
line2.append(talk['__end'].strftime('%H:%M'))

with open(os.path.join(DATA_DIR, stream, 'line1.txt.tmp'), 'w+') as f:
if talk:
f.write(talk['title'])
else:
f.write('')

with open(os.path.join(DATA_DIR, stream, 'line2.txt.tmp'), 'w+') as f:
f.write(' - '.join(line2))

for i in ('line1', 'line2'):
os.replace(
os.path.join(DATA_DIR, stream, f'{i}.txt.tmp'),
os.path.join(DATA_DIR, stream, f'{i}.txt'),
)

LOG.info(f'wrote info for {stream}')
14 changes: 14 additions & 0 deletions bundlewrap/bundles/loudness-rendering/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@
'triggers': set(),
}

directories['/opt/loudness-rendering/data'] = {
'owner': 'voc',
}

files['/opt/loudness-rendering/config.json'] = {
'content': repo.libs.faults.dict_as_json(node.metadata.get('loudness-rendering')),
}

files['/usr/local/bin/loudness_info_updater'] = {
'source': 'updater.py',
'mode': '0755',
}


for stream, config in node.metadata.get('loudness-rendering/streams').items():
files[f'/usr/local/lib/systemd/system/{stream}_loudness.service'] = {
'source': 'service',
Expand Down
8 changes: 8 additions & 0 deletions bundlewrap/bundles/loudness-rendering/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
'ffmpeg': {},
},
},
'systemd-timers': {
'timers': {
'loudness_info_updater': {
'command': '/usr/local/bin/loudness_info_updater',
'when': 'minutely',
},
},
},
}


Expand Down
5 changes: 5 additions & 0 deletions bundlewrap/bundles/mdadm/metadata.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
defaults = {
'apt': {
'packages': {
'mdadm': {},
},
},
'mqtt-monitoring': {
'plugins': {
'raid_mdstat',
Expand Down
3 changes: 3 additions & 0 deletions bundlewrap/bundles/mixer-common/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@
'needs': {
'action:i3pystatus_create_virtualenv',
},
'after': {
'pkg_apt:',
},
'triggered': True,
}

Expand Down
2 changes: 1 addition & 1 deletion bundlewrap/bundles/mixer-common/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'i3status': {},
'irssi': {},
'kitty': {},
'netcat': {},
'netcat-openbsd': {},
'slim': {},
'x11-utils': {},
'x11-xserver-utils': {},
Expand Down
12 changes: 11 additions & 1 deletion bundlewrap/bundles/thinkfan/files/configwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,21 @@
(127, 59, 32767)
"""

filtered_hwids = set()
hwids = check_output(['find', '/sys/devices/platform', '-type', 'f', '-iname', 'temp*_input']).decode().splitlines()

for hwid in hwids:
try:
with open(hwid) as f:
# atleast on mixer96, temp2_input exists, but does fail when reading
f.read()
filtered_hwids.add(hwid)
except Exception as e:
print(f'could not open {hwid} for reading: {e!r}')

with open('/etc/thinkfan.conf', 'w') as f:
f.write(CONFIG_TEMPLATE.format(
hwmon='\n'.join([
f'hwmon {i}' for i in sorted(hwids)
f'hwmon {i}' for i in sorted(filtered_hwids)
]),
))
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ trap 'cd /;rm -Rf "$tmpdir"' EXIT
schedule="$(cat /opt/voc/schedule_url)"
if [[ -n "$schedule" ]]
then
curl -qo "$tmpdir/schedule.xml" "$schedule"
curl -qo "$tmpdir/schedule.json" "$schedule"
curl_exit=$?

if [[ $curl_exit -ne 0 ]]
then
voc2alert "error" "schedule" "Downloading schedule from $schedule failed: curl exited $curl_exit"
else
xmllint "$tmpdir/schedule.xml" >/dev/null
python -m json.tool >/dev/null <"$tmpdir/schedule.json"
validate_exit=$?

if [[ $validate_exit -ne 0 ]]
then
voc2alert "error" "schedule" "Downloading schedule from $schedule failed: xmllint exited $validate_exit"
voc2alert "error" "schedule" "Downloading schedule from $schedule failed: python -m json.tool exited $validate_exit"
else
sha_old="$(sha256sum /opt/voc/schedule.xml | cut -d' ' -f1)"
sha_new="$(sha256sum "$tmpdir/schedule.xml" | cut -d' ' -f1)"
sha_old="$(sha256sum /opt/voc/schedule.json | cut -d' ' -f1)"
sha_new="$(sha256sum "$tmpdir/schedule.json" | cut -d' ' -f1)"

if [[ "$sha_old" != "$sha_new" ]]
then
chmod go+r "$tmpdir/schedule.xml"
mv "$tmpdir/schedule.xml" "/opt/voc/schedule.xml"
chmod go+r "$tmpdir/schedule.json"
mv "$tmpdir/schedule.json" "/opt/voc/schedule.json"
voc2alert "info" "schedule" "Downloading schedule from $schedule succeeded"
fi
fi
Expand Down

0 comments on commit c1157c2

Please sign in to comment.