50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
import requests
|
|
import time
|
|
import argparse
|
|
import multiprocessing
|
|
|
|
INGEST_URL = "https://emiapi.reynafamily.com/live-captions/ingest"
|
|
|
|
def run_distribution(in_queue, args):
|
|
print("[Distribute] Starting distribution service...")
|
|
|
|
while True:
|
|
try:
|
|
payload = in_queue.get()
|
|
if payload is None: break
|
|
|
|
if args.ingest:
|
|
delay = 1
|
|
max_delay = 15
|
|
success = False
|
|
|
|
while not success:
|
|
try:
|
|
response = requests.post(INGEST_URL, json=payload, timeout=5)
|
|
if response.status_code == 200:
|
|
success = True
|
|
else:
|
|
print(f"[Distribute Error] {response.status_code}. Retrying in {delay}s...")
|
|
except Exception as e:
|
|
print(f"[Distribute Error] {e}. Retrying in {delay}s...")
|
|
|
|
if not success:
|
|
time.sleep(delay)
|
|
delay = min(delay * 2, max_delay)
|
|
|
|
print(f"[Distribute] Sent payload: {list(payload.keys())}")
|
|
else:
|
|
print(f"[Distribute] Local display (ingest disabled): {payload}")
|
|
|
|
except Exception as e:
|
|
print(f"[Distribute] Error: {e}")
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("-i", "--ingest", action="store_true")
|
|
args = parser.parse_args()
|
|
|
|
# Dummy queue for testing
|
|
in_q = multiprocessing.Queue()
|
|
run_distribution(in_q, args)
|