#!/usr/bin/env python3 from pathlib import Path nginx_conf = Path('/etc/nginx/nginx.conf') text = nginx_conf.read_text() old_block = """ application live { live on; record off; allow publish 127.0.0.1; deny publish all; allow play all; } """ new_block = """ application live { live on; record off; hls on; hls_path /var/www/html/hls; hls_fragment 2s; hls_playlist_length 12s; hls_continuous on; hls_cleanup on; allow publish 127.0.0.1; deny publish all; allow play all; } """ if new_block in text: print('HLS already enabled in live application block') raise SystemExit(0) if old_block not in text: raise SystemExit('Could not find expected live application block to patch') text = text.replace(old_block, new_block, 1) nginx_conf.write_text(text) print('Patched nginx rtmp live application block with HLS settings')