Skip to content

Commit

Permalink
It seems that just checking if the segment exists on disk might make …
Browse files Browse the repository at this point in the history
…it return the segment while it's still being written to
  • Loading branch information
thomaserlang committed Dec 13, 2023
1 parent dfac281 commit 8e9305c
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions seplis_play_server/transcoders/hls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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):
Expand Down

0 comments on commit 8e9305c

Please sign in to comment.