From bf6970938d9cbd94fb6fc606d1c65b938865e944 Mon Sep 17 00:00:00 2001 From: Thomas Erlang Date: Sun, 10 Dec 2023 19:43:25 +0100 Subject: [PATCH] Since we changed the hls manifest to a vod we have to get the first and latest segment transcoded another way --- seplis_play_server/routes/hls.py | 2 -- seplis_play_server/transcoders/hls.py | 22 ++++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/seplis_play_server/routes/hls.py b/seplis_play_server/routes/hls.py index 7998585..b893326 100644 --- a/seplis_play_server/routes/hls.py +++ b/seplis_play_server/routes/hls.py @@ -1,6 +1,4 @@ -import asyncio import os.path -import anyio from fastapi import APIRouter, HTTPException, Depends, Response from fastapi.responses import FileResponse diff --git a/seplis_play_server/transcoders/hls.py b/seplis_play_server/transcoders/hls.py index 08d4385..17e973b 100644 --- a/seplis_play_server/transcoders/hls.py +++ b/seplis_play_server/transcoders/hls.py @@ -65,16 +65,18 @@ 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) - if await anyio.to_thread.run_sync(os.path.exists, f): - async with async_open(f, "r") as afp: - async for line in afp: - if not '#' in line: - m = re.search(r'(\d+)\.m4s', line) - last = int(m.group(1)) - if not first: - first = last + first, last = (-1, 0) + if await anyio.to_thread.run_sync(os.path.exists, transcode_folder): + files = await anyio.to_thread.run_sync(os.listdir, transcode_folder) + for f in files: + m = re.search(r'media(\d+)\.m4s', f) + if m: + v = int(m.group(1)) + if v > last: + last = v + if v < first or first == -1: + first = v + first = int(m.group(1)) else: logger.debug(f'No media file {f}') return (first, last)