JAYNESTV commited on
Commit
b141afe
·
verified ·
1 Parent(s): 85ad1b8

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -1
app.py CHANGED
@@ -436,7 +436,20 @@ async def hls_file(sid: str, path: str):
436
  full = os.path.join(s["dir"], path)
437
  if not os.path.exists(full):
438
  return err(404, "Haipatikani")
439
- if path.endswith(".m3u8"):
 
 
 
 
 
 
 
 
 
 
 
 
 
440
  r = FileResponse(full, media_type="application/vnd.apple.mpegurl",
441
  headers={"Cache-Control": "no-store"})
442
  else:
 
436
  full = os.path.join(s["dir"], path)
437
  if not os.path.exists(full):
438
  return err(404, "Haipatikani")
439
+ if path.endswith("index.m3u8"):
440
+ try:
441
+ with open(full, "r", errors="ignore") as f:
442
+ txt = f.read()
443
+ except OSError:
444
+ return err(404, "Haipatikani")
445
+ lines = txt.splitlines()
446
+ idx = [i for i, l in enumerate(lines) if l.startswith("#EXTINF")]
447
+ n = int(os.environ.get("LIVE_DELAY", "2")) # ficha segment za mwisho = buffer ya ziada
448
+ if n > 0 and len(idx) > n + 2:
449
+ txt = "\n".join(lines[:idx[-n]]) + "\n"
450
+ r = Response(txt, media_type="application/vnd.apple.mpegurl",
451
+ headers={"Cache-Control": "no-store"})
452
+ elif path.endswith(".m3u8"):
453
  r = FileResponse(full, media_type="application/vnd.apple.mpegurl",
454
  headers={"Cache-Control": "no-store"})
455
  else: