check if stream_hls_url exists before we exec the recording

This commit is contained in:
deflax 2024-01-12 22:40:37 +02:00
parent 18bb202796
commit 39ab8c23d2
2 changed files with 18 additions and 10 deletions

View file

@ -1,7 +1,8 @@
import os
import time
import logging
import json
import time
import requests
from datetime import datetime
from flask import Flask, render_template, jsonify, request
from apscheduler.schedulers.background import BackgroundScheduler
@ -154,8 +155,14 @@ def exec_recorder(stream_id, stream_hls_url):
output_file = current_datetime + ".mp4"
if rechead != "":
logger_job.error('Recorder is already started. Refusing to start another rec job.')
return False
else:
# Check if the stream_hls_url returns 200
req_counter = 0
while True:
req_counter += 1
if requests.get(stream_hls_url).status_code == 200:
logger_job.warning(f'{stream_hls_url} accessible after {req_counter} attempts.')
break
logger_job.warning(f'Starting recording job for {output_file}')
rechead = stream_id
ffmpeg = (

View file

@ -8,3 +8,4 @@ waitress==2.1.2
Werkzeug==3.0.1
APScheduler==3.10.4
python-ffmpeg==2.0.10
requests==2.31.0