Made the player more static.
This commit is contained in:
parent
4479013712
commit
8f9d3e27f3
3 changed files with 15 additions and 19 deletions
|
|
@ -285,7 +285,10 @@ class Main:
|
||||||
raise web.HTTPBadRequest(reason='file is required')
|
raise web.HTTPBadRequest(reason='file is required')
|
||||||
|
|
||||||
return web.Response(
|
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={
|
headers={
|
||||||
'Content-Type': 'application/x-mpegURL',
|
'Content-Type': 'application/x-mpegURL',
|
||||||
'Cache-Control': 'no-cache',
|
'Cache-Control': 'no-cache',
|
||||||
|
|
@ -308,7 +311,6 @@ class Main:
|
||||||
raise web.HTTPBadRequest(reason='segment is required')
|
raise web.HTTPBadRequest(reason='segment is required')
|
||||||
|
|
||||||
segmenter = Segments(
|
segmenter = Segments(
|
||||||
config=self.config,
|
|
||||||
segment_index=int(segment),
|
segment_index=int(segment),
|
||||||
segment_duration=float('{:.6f}'.format(
|
segment_duration=float('{:.6f}'.format(
|
||||||
float(sd if sd else M3u8.segment_duration))),
|
float(sd if sd else M3u8.segment_duration))),
|
||||||
|
|
@ -317,7 +319,7 @@ class Main:
|
||||||
)
|
)
|
||||||
|
|
||||||
return web.Response(
|
return web.Response(
|
||||||
body=await segmenter.stream(file),
|
body=await segmenter.stream(download_path=self.config.download_path, file=file),
|
||||||
headers={
|
headers={
|
||||||
'Content-Type': 'video/mpegts',
|
'Content-Type': 'video/mpegts',
|
||||||
'Connection': 'keep-alive',
|
'Connection': 'keep-alive',
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ import os
|
||||||
from urllib.parse import quote
|
from urllib.parse import quote
|
||||||
from Utils import calcDownloadPath
|
from Utils import calcDownloadPath
|
||||||
from .ffprobe import FFProbe
|
from .ffprobe import FFProbe
|
||||||
from Config import Config
|
|
||||||
|
|
||||||
|
|
||||||
class M3u8:
|
class M3u8:
|
||||||
|
|
@ -11,17 +10,15 @@ class M3u8:
|
||||||
ok_acodecs: tuple = ('aac', 'mp3',)
|
ok_acodecs: tuple = ('aac', 'mp3',)
|
||||||
|
|
||||||
segment_duration: float = 10.000000
|
segment_duration: float = 10.000000
|
||||||
config: Config = None
|
url: str = None
|
||||||
download_path: str = None
|
|
||||||
|
|
||||||
def __init__(self, config: Config, segment_duration: float = 6.000000):
|
def __init__(self, url: str, segment_duration: float = 6.000000):
|
||||||
self.config = config
|
self.url = url
|
||||||
self.download_path = self.config.download_path
|
|
||||||
self.segment_duration = float(segment_duration)
|
self.segment_duration = float(segment_duration)
|
||||||
|
|
||||||
def make_stream(self, file: str):
|
def make_stream(self, download_path: str, file: str):
|
||||||
realFile: str = calcDownloadPath(
|
realFile: str = calcDownloadPath(
|
||||||
basePath=self.download_path,
|
basePath=download_path,
|
||||||
folder=file,
|
folder=file,
|
||||||
createPath=False
|
createPath=False
|
||||||
)
|
)
|
||||||
|
|
@ -68,7 +65,7 @@ class M3u8:
|
||||||
else:
|
else:
|
||||||
m3u8 += f"#EXTINF:{segmentSize}, nodesc\n"
|
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:
|
if len(segmentParams) > 0:
|
||||||
m3u8 += '?'+'&'.join([f"{key}={value}" for key,
|
m3u8 += '?'+'&'.join([f"{key}={value}" for key,
|
||||||
value in segmentParams.items()])
|
value in segmentParams.items()])
|
||||||
|
|
|
||||||
|
|
@ -8,25 +8,22 @@ from Config import Config
|
||||||
|
|
||||||
log = logging.getLogger('segments')
|
log = logging.getLogger('segments')
|
||||||
|
|
||||||
|
|
||||||
class Segments:
|
class Segments:
|
||||||
config: Config = None
|
|
||||||
download_path: str = None
|
|
||||||
segment_duration: int
|
segment_duration: int
|
||||||
segment_index: int
|
segment_index: int
|
||||||
vconvert: bool
|
vconvert: bool
|
||||||
aconvert: bool
|
aconvert: bool
|
||||||
|
|
||||||
def __init__(self, config: Config, segment_index: int, segment_duration: float, vconvert: bool, aconvert: bool):
|
def __init__(self, segment_index: int, segment_duration: float, vconvert: bool, aconvert: bool):
|
||||||
self.config = config
|
|
||||||
self.download_path = self.config.download_path
|
|
||||||
self.segment_duration = float(segment_duration)
|
self.segment_duration = float(segment_duration)
|
||||||
self.segment_index = int(segment_index)
|
self.segment_index = int(segment_index)
|
||||||
self.vconvert = bool(vconvert)
|
self.vconvert = bool(vconvert)
|
||||||
self.aconvert = bool(aconvert)
|
self.aconvert = bool(aconvert)
|
||||||
|
|
||||||
async def stream(self, file: str) -> bytes:
|
async def stream(self, download_path: str, file: str) -> bytes:
|
||||||
realFile: str = calcDownloadPath(
|
realFile: str = calcDownloadPath(
|
||||||
basePath=self.download_path,
|
basePath=download_path,
|
||||||
folder=file,
|
folder=file,
|
||||||
createPath=False
|
createPath=False
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue