Skip to content

Commit

Permalink
Since we changed the hls manifest to a vod we have to get the first a…
Browse files Browse the repository at this point in the history
…nd latest segment transcoded another way
  • Loading branch information
thomaserlang committed Dec 10, 2023
1 parent d4b8762 commit bf69709
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 0 additions & 2 deletions seplis_play_server/routes/hls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import asyncio
import os.path
import anyio
from fastapi import APIRouter, HTTPException, Depends, Response
from fastapi.responses import FileResponse

Expand Down
22 changes: 12 additions & 10 deletions seplis_play_server/transcoders/hls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit bf69709

Please sign in to comment.