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