diff --git a/backend/stream_providers.py b/backend/stream_providers.py index 4532104..2c80601 100755 --- a/backend/stream_providers.py +++ b/backend/stream_providers.py @@ -68,10 +68,11 @@ class MetaParser(html.parser.HTMLParser): return self.handle_starttag_input(attrs) class StreamData(): - def __init__(self, upstream, ctype, thumbnail, title, description, override): + def __init__(self, upstream, ctype, proxy_ctype, thumbnail, title, description, override): self.values = {} self.values["upstream"] = upstream self.values["ctype"] = ctype + self.values["proxy_ctype"] = proxy_ctype self.values["thumbnail"] = thumbnail self.values["title"] = title self.values["description"] = description @@ -85,6 +86,8 @@ class StreamData(): return self.values.get("upstream") def ctype(self): return self.values.get("ctype") + def proxy_ctype(self): + return self.values.get("ctype") def thumbnail(self): return self.values.get("thumbnail") def title(self): @@ -135,6 +138,7 @@ class StreamProvider(): def init_stream(self): stream = {} stream["upstream"] = None + stream["proxy_ctype"] = None stream["ctype"] = None stream["thumbnail"] = None stream["title"] = None @@ -143,6 +147,7 @@ class StreamProvider(): return stream def process(self): data = self.stream() + proxy_ctype = data.proxy_ctype() if not isinstance(data.upstream(), str) or isinstance(data.ctype(), str): return data proxies = None @@ -164,7 +169,9 @@ class StreamProvider(): ctype = None elif "mpegurl" in ctype: ctype = "application/vnd.apple.mpegurl" - return StreamData(data.upstream(), ctype, data.thumbnail(), data.title(), data.description(), data.override) + if ctype == "application/octet-stream" and isinstance(proxy_ctype, str): + ctype = proxy_ctype + return StreamData(data.upstream(), ctype, proxy_ctype, data.thumbnail(), data.title(), data.description(), data.override) async def run(self): data = None try: @@ -188,10 +195,10 @@ class StreamlinkRunner(StreamProvider): for key in reversed(streams): stream = streams.get(key) if hasattr(stream, "url"): - return StreamData(stream.url, self.extract_mime(stream.url), None, None, None, False) + return StreamData(stream.url, self.extract_mime(stream.url), None, None, None, None, False) except Exception as e: self.logger.info("%s <%s>", e, self.upstream) - return StreamData(None, None, None, None, None, False) + return StreamData(None, None, None, None, None, None, False) class YoutubeRunner(StreamProvider): def stream(self): @@ -249,7 +256,7 @@ class SeafileRunner(StreamProvider): stream_data["title"] = json_data.get("filePath") stream_data["upstream"] = json_data.get("rawPath") if json_data.get("filePath").lower().endswith(".mp4"): - stream_data["ctype"] = "video/mp4" + stream_data["proxy_ctype"] = "video/mp4" return StreamData(**stream_data) class MetaProvider(StreamProvider): @@ -326,7 +333,7 @@ async def get_any(upstream, proxy, logger): tasks.append(asyncio.create_task(get_ytdl(upstream, proxy, logger))) tasks.append(asyncio.create_task(get_meta(upstream, proxy, logger))) - result = StreamData(None, None, None, None, None, False) + result = StreamData(None, None, None, None, None, None, False) for task in asyncio.as_completed(tasks): temp_result = await task if isinstance(temp_result, StreamData):