add provider test

This commit is contained in:
Roy Olav Purser 2021-05-14 17:28:10 +02:00
parent db96538980
commit 7531786cfb
Signed by: roypur
GPG Key ID: E14D26A036F21656

View File

@ -113,10 +113,13 @@ class UpstreamHandler():
async def setup(self, handler):
self.provider = handler.get_query_argument("provider", None)
render_str = handler.get_query_argument("render", "false")
if render_str.lower() == "true":
self.render = True
self.stream = False
self.render = False
self.stream = False
if self.provider in providers.keys():
if render_str.lower() == "true":
self.render = True
else:
self.stream = True
path = handler.request.path
if self.provider == "youtube":
path = path.strip("/")
@ -316,19 +319,18 @@ class MainHandler(tornado.web.RequestHandler):
async def handle_stream(self, handler, redir):
upstream = None
if handler.proxy is not None:
try:
logger.info(proxy)
streams = handler.proxy.stream().streams(handler.upstream)
except Exception as e:
logger.info(e)
else:
for key in reversed(streams):
stream = streams.get(key)
logger.info(stream)
if hasattr(stream, "url"):
upstream = stream.url
break
try:
logger.info(handler.proxy)
streams = handler.proxy.stream().streams(handler.upstream)
except Exception as e:
logger.info(e)
else:
for key in reversed(streams):
stream = streams.get(key)
logger.info(stream)
if hasattr(stream, "url"):
upstream = stream.url
break
else:
logger.info(f'invalid provider ({handler.provider})')
self.set_status(404)
@ -345,7 +347,7 @@ class MainHandler(tornado.web.RequestHandler):
logger.info(upstream)
data = None
if "mpegurl" in ctype.lower():
data = await rewrite(upstream, proxy)
data = await rewrite(upstream, handler.proxy)
logger.info(data)
if isinstance(data, str):
self.set_header("Content-Type", "application/vnd.apple.mpegurl")