Proxy live-stream
This commit is contained in:
1 parent
18036cd135
commit
c2d5ca0d94
1 file changed
+23
-2
+23
-2
@@ -171,12 +171,33 @@ def start_recount():
|
||||
|
||||
return jsonify({
|
||||
"success": True,
|
||||
"stream_url": f"{RECOUNT_API_URL}/api/live-video",
|
||||
"stream_url": "/api/proxy-stream",
|
||||
"file": Path(mp4_path).name,
|
||||
"path": mp4_path,
|
||||
})
|
||||
|
||||
|
||||
@app.route("/api/proxy-stream")
|
||||
def api_proxy_stream():
|
||||
try:
|
||||
resp = _http_session.get(f"{RECOUNT_API_URL}/api/live-video", stream=True, timeout=5)
|
||||
if resp.status_code != 200:
|
||||
return Response("stream unavailable", status=502)
|
||||
|
||||
def generate():
|
||||
for chunk in resp.iter_content(chunk_size=8192):
|
||||
if chunk:
|
||||
yield chunk
|
||||
resp.close()
|
||||
|
||||
return Response(
|
||||
generate(),
|
||||
mimetype=resp.headers.get("Content-Type", "multipart/x-mixed-replace; boundary=frame"),
|
||||
)
|
||||
except Exception:
|
||||
return Response("stream unavailable", status=502)
|
||||
|
||||
|
||||
@app.route("/api/stop-recount", methods=["POST"])
|
||||
def stop_recount():
|
||||
global _current_file
|
||||
@@ -198,7 +219,7 @@ def api_state():
|
||||
if current_file:
|
||||
result["file"] = current_file
|
||||
result["file_name"] = Path(current_file).name
|
||||
result["stream_url"] = f"{RECOUNT_API_URL}/api/live-video"
|
||||
result["stream_url"] = "/api/proxy-stream"
|
||||
batch_num, date_str = _parse_filename(Path(current_file).name)
|
||||
if batch_num is not None:
|
||||
result["batch_number"] = batch_num
|
||||
|
||||
Reference in new issue
Block a user