Made the player more static.

This commit is contained in:
ArabCoders 2023-12-31 18:51:59 +03:00
parent 4479013712
commit 8f9d3e27f3
3 changed files with 15 additions and 19 deletions

View file

@ -285,7 +285,10 @@ class Main:
raise web.HTTPBadRequest(reason='file is required')
return web.Response(
text=M3u8(self.config).make_stream(file),
text=M3u8(url=f"{self.config.url_host}{self.config.url_prefix}").make_stream(
download_path=self.config.download_path,
file=file
),
headers={
'Content-Type': 'application/x-mpegURL',
'Cache-Control': 'no-cache',
@ -308,7 +311,6 @@ class Main:
raise web.HTTPBadRequest(reason='segment is required')
segmenter = Segments(
config=self.config,
segment_index=int(segment),
segment_duration=float('{:.6f}'.format(
float(sd if sd else M3u8.segment_duration))),
@ -317,7 +319,7 @@ class Main:
)
return web.Response(
body=await segmenter.stream(file),
body=await segmenter.stream(download_path=self.config.download_path, file=file),
headers={
'Content-Type': 'video/mpegts',
'Connection': 'keep-alive',

View file

@ -3,7 +3,6 @@ import os
from urllib.parse import quote
from Utils import calcDownloadPath
from .ffprobe import FFProbe
from Config import Config
class M3u8:
@ -11,17 +10,15 @@ class M3u8:
ok_acodecs: tuple = ('aac', 'mp3',)
segment_duration: float = 10.000000
config: Config = None
download_path: str = None
url: str = None
def __init__(self, config: Config, segment_duration: float = 6.000000):
self.config = config
self.download_path = self.config.download_path
def __init__(self, url: str, segment_duration: float = 6.000000):
self.url = url
self.segment_duration = float(segment_duration)
def make_stream(self, file: str):
def make_stream(self, download_path: str, file: str):
realFile: str = calcDownloadPath(
basePath=self.download_path,
basePath=download_path,
folder=file,
createPath=False
)
@ -68,7 +65,7 @@ class M3u8:
else:
m3u8 += f"#EXTINF:{segmentSize}, nodesc\n"
m3u8 += f"{self.config.url_host}{self.config.url_prefix}segments/{i}/{quote(file)}"
m3u8 += f"{self.url}segments/{i}/{quote(file)}"
if len(segmentParams) > 0:
m3u8 += '?'+'&'.join([f"{key}={value}" for key,
value in segmentParams.items()])

View file

@ -8,25 +8,22 @@ from Config import Config
log = logging.getLogger('segments')
class Segments:
config: Config = None
download_path: str = None
segment_duration: int
segment_index: int
vconvert: bool
aconvert: bool
def __init__(self, config: Config, segment_index: int, segment_duration: float, vconvert: bool, aconvert: bool):
self.config = config
self.download_path = self.config.download_path
def __init__(self, segment_index: int, segment_duration: float, vconvert: bool, aconvert: bool):
self.segment_duration = float(segment_duration)
self.segment_index = int(segment_index)
self.vconvert = bool(vconvert)
self.aconvert = bool(aconvert)
async def stream(self, file: str) -> bytes:
async def stream(self, download_path: str, file: str) -> bytes:
realFile: str = calcDownloadPath(
basePath=self.download_path,
basePath=download_path,
folder=file,
createPath=False
)