fix error message
All checks were successful
continuous-integration/drone Build is passing

This commit is contained in:
Roy Olav Purser 2022-02-05 21:56:06 +01:00
parent 78e5974a92
commit 52f51bc6d5
Signed by: roypur
GPG Key ID: E14D26A036F21656

View File

@ -85,6 +85,14 @@ class UpstreamHandler:
future.cancel()
class NoDataError(Exception):
pass
class MissingTemplateError(Exception):
pass
class MainHandler(tornado.web.RequestHandler):
async def handle_any(self):
handler = UpstreamHandler()
@ -99,11 +107,10 @@ class MainHandler(tornado.web.RequestHandler):
self.set_status(404)
self.write("Stream not found. (provider missing)")
async def get_data(self, handler):
async def get_data(self, handler) -> tuple[dict[str, str], str, str]:
video_info = None
meta = None
title = None
if config.template_script is not None and config.template_html is not None:
if config.template_script is None or config.template_html is None:
raise MissingTemplateError()
provider_data = None
if handler.provider.startswith("nextcloud"):
provider_data = await stream_providers.get_nextcloud(
@ -118,7 +125,7 @@ class MainHandler(tornado.web.RequestHandler):
handler.upstream, handler.proxy, logger
)
if provider_data is None:
return (None, None, None)
raise NoDataError()
video_info = {}
if handler.direct:
@ -135,21 +142,31 @@ class MainHandler(tornado.web.RequestHandler):
video_info["poster"] = proxied[1]
video_info["ctype"] = provider_data.ctype()
meta = provider_data.meta()
title = provider_data.title()
return (video_info, meta, title)
return (video_info, provider_data.meta(), provider_data.title())
async def handle_raw(self, handler):
try:
video_info = (await self.get_data(handler))[0]
if video_info is not None:
self.redirect(url=video_info["upstream"], status=303)
else:
except NoDataError:
self.set_status(404)
self.write("HTML template missing.")
except MissingTemplateError:
self.set_status(404)
self.write("Video not found.")
async def handle_render(self, handler):
try:
video_info, meta, title = await self.get_data(handler)
if video_info is not None:
except NoDataError:
self.set_status(404)
self.write("HTML template missing.")
return
except MissingTemplateError:
self.set_status(404)
self.write("Video not found.")
return
script = config.template_script.generate(info=json.dumps(video_info))
b64 = str(base64.b64encode(script), "ascii")
data = {}
@ -158,13 +175,8 @@ class MainHandler(tornado.web.RequestHandler):
data["videojs_version"] = config.videojs_version
data["chromecast_version"] = config.chromecast_version
data["font_awesome_version"] = config.font_awesome_version
rendered_html = config.template_html.generate(
data=data, meta=meta, title=title
)
rendered_html = config.template_html.generate(data=data, meta=meta, title=title)
self.write(rendered_html)
else:
self.set_status(404)
self.write("HTML template missing.")
async def get(self):
await self.handle_any()