From 717b033791a60707ffe634b9faef4281e748fa74 Mon Sep 17 00:00:00 2001 From: ninya9k Date: Mon, 12 Apr 2021 04:52:20 +0000 Subject: [PATCH] skip existence check when counting segment views on /stream.mp4 --- app.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index 8da23b7..a8e66f7 100644 --- a/app.py +++ b/app.py @@ -173,13 +173,13 @@ def segment_arbitrary(n): response.set_cookie('token', token) return response -def _view_segment(n, token=None): +def _view_segment(n, token=None, check_exists=True): # n is None if segment_hook is called in ConcatenatedSegments and the current segment is init.mp4 if n == None: return # technically this is a race condition - if not os.path.isfile(os.path.join(SEGMENTS_DIR, f'stream{n}.m4s')): + if check_exists and not os.path.isfile(os.path.join(SEGMENTS_DIR, f'stream{n}.m4s')): return with lock: @@ -194,7 +194,7 @@ def stream(): segments_cache=SEGMENTS_CACHE, segment_offset=max(VIEWS_PERIOD // HLS_TIME, 2), stream_timeout=HLS_TIME + 2, - segment_hook=lambda n: _view_segment(n, token)) + segment_hook=lambda n: _view_segment(n, token, check_exists=False)) file_wrapper = werkzeug.wrap_file(request.environ, concatenated_segments) response = Response(file_wrapper, mimetype='video/mp4') response.headers['Cache-Control'] = 'no-cache'