Reformat files
This commit is contained in:
parent
1ea363ecbd
commit
255961b944
|
@ -1,6 +1,7 @@
|
|||
import os
|
||||
import re
|
||||
|
||||
|
||||
def load_env(filename=".env"):
|
||||
env_vars = {}
|
||||
with open(filename) as f:
|
||||
|
@ -10,10 +11,12 @@ def load_env(filename=".env"):
|
|||
env_vars[key] = value
|
||||
return env_vars
|
||||
|
||||
|
||||
def count_servers(env_vars):
|
||||
server_keys = [key for key in env_vars if re.match(r"PORT_\d+", key)]
|
||||
return len(server_keys)
|
||||
|
||||
|
||||
def generate_docker_compose(env_vars, num_servers):
|
||||
ip = env_vars.get("IP")
|
||||
services = []
|
||||
|
@ -45,6 +48,7 @@ services:
|
|||
with open("docker-compose.yml", "w") as f:
|
||||
f.write(compose_content)
|
||||
|
||||
|
||||
def generate_mediamtx_files(env_vars, num_servers):
|
||||
# os.makedirs("mediamtx")
|
||||
mediamtx_dir = "mediamtx"
|
||||
|
@ -58,7 +62,9 @@ def generate_mediamtx_files(env_vars, num_servers):
|
|||
port = env_vars.get(f"PORT_{i}")
|
||||
listener_port = env_vars.get(f"LISTENER_PORT_{i}")
|
||||
|
||||
generated_content = template_content.replace("{{WEBRTC_PORT}}", port).replace("{{WEBRTC_LISTENER_PORT}}", listener_port)
|
||||
generated_content = template_content.replace("{{WEBRTC_PORT}}", port).replace(
|
||||
"{{WEBRTC_LISTENER_PORT}}", listener_port
|
||||
)
|
||||
|
||||
with open(f"mediamtx/mediamtx_{i}.yml", "w") as f:
|
||||
f.write(generated_content)
|
||||
|
@ -71,13 +77,14 @@ def generate_mediamtx_files(env_vars, num_servers):
|
|||
os.remove(f"mediamtx/{file}")
|
||||
print(f"Removed extra file: {file}")
|
||||
|
||||
|
||||
def generate_start_bat(num_servers):
|
||||
with open("templates/start.bat", "r") as template_file:
|
||||
bat_template = template_file.read()
|
||||
|
||||
obs_instances = ""
|
||||
for i in range(1, num_servers + 1):
|
||||
obs_instance = f"""
|
||||
obs_instance = f""" # noqa: E501
|
||||
echo Launching OBS instance {i}
|
||||
start /MIN "OBS{i}" /D "C:\\Program Files\\obs-studio\\bin\\64bit" "obs64.exe" --profile "Profile{i}" --collection "Profile{i}" --multi --startstreaming
|
||||
timeout /t 1 >nul
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
import os
|
||||
from config import *
|
||||
from config import (
|
||||
count_servers,
|
||||
generate_docker_compose,
|
||||
generate_mediamtx_files,
|
||||
generate_start_bat,
|
||||
load_env,
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
env_vars = load_env(".env")
|
||||
|
@ -9,5 +15,6 @@ def main():
|
|||
generate_mediamtx_files(env_vars, num_servers)
|
||||
generate_start_bat(num_servers)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
Loading…
Reference in New Issue