sc16 / stream_videos.py
OptiJuegos's picture
Upload 3 files
9db385b verified
raw
history blame
1.82 kB
import os
import subprocess
from multiprocessing import Process
import uvicorn
from fastapi import FastAPI
import logging
import threading
import signal
import time
app = FastAPI()
# Configure logger
logging.basicConfig(level=logging.INFO)
# No Rtmp or Ffmpeg related variables
def start_playit_server():
try:
logging.info("Starting playit-linux-amd64")
subprocess.run("./playit-linux-amd64", shell=True, check=True)
except subprocess.CalledProcessError as e:
logging.error(f"Error running playit-linux-amd64: {e}")
def start_impostor_server():
try:
logging.info("Starting Impostor.Server")
subprocess.run("./hlds_linux", shell=True, check=True)
except subprocess.CalledProcessError as e:
logging.error(f"Error running Impostor.Server: {e}")
def monitor_playit_process():
while True:
if not playit_process.is_alive():
logging.info("Playit process stopped. Restarting...")
start_playit_process()
time.sleep(1) # Check every second
def start_playit_process():
global playit_process
playit_process = Process(target=start_playit_server)
playit_process.start()
@app.get("/")
async def read_root():
return {"message": "Hello World"}
if __name__ == "__main__":
# Start playit process in a separate process
start_playit_process()
# Start Impostor.Server in a separate process
global impostor_server_process
impostor_server_process = Process(target=start_impostor_server)
impostor_server_process.start()
# Start the monitor thread
monitor_thread = threading.Thread(target=monitor_playit_process)
monitor_thread.start()
# Start the FastAPI server
uvicorn.run(app, host="0.0.0.0", port=7860)