From 8e9305c6a27bdd632dcb0a87733bc56d298110ed Mon Sep 17 00:00:00 2001 From: Thomas Erlang Date: Wed, 13 Dec 2023 23:13:42 +0100 Subject: [PATCH] It seems that just checking if the segment exists on disk might make it return the segment while it's still being written to --- seplis_play_server/transcoders/hls.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/seplis_play_server/transcoders/hls.py b/seplis_play_server/transcoders/hls.py index 9e474db..159fd61 100644 --- a/seplis_play_server/transcoders/hls.py +++ b/seplis_play_server/transcoders/hls.py @@ -67,7 +67,7 @@ async def wait_for(): @classmethod async def first_last_transcoded_segment(cls, transcode_folder: str): f = os.path.join(transcode_folder, cls.media_name) - first, last = (0, 0) + first, last = (-1, -1) if await anyio.to_thread.run_sync(os.path.exists, f): async with async_open(f, "r") as afp: async for line in afp: @@ -83,10 +83,8 @@ async def first_last_transcoded_segment(cls, transcode_folder: str): @classmethod async def is_segment_ready(cls, transcode_folder: str, segment: int): - return await anyio.to_thread.run_sync( - os.path.exists, - cls.get_segment_path(transcode_folder, segment) - ) + _, last_segment = await cls.first_last_transcoded_segment(transcode_folder) + return last_segment >= segment @staticmethod def get_segment_path(transcode_folder: str, segment: int):