template stuff

This commit is contained in:
Roy Olav Purser 2021-05-13 14:22:11 +02:00
parent 7d821b0ea7
commit 5ebdfb9747
Signed by: roypur
GPG Key ID: E14D26A036F21656
2 changed files with 11 additions and 6 deletions

View File

@ -1,7 +1,7 @@
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="alternate" type="application/json+oembed" href="{{ origin }}?provider={{ provider }}&embed=true">
<link rel="alternate" type="application/json+oembed" href="{{ origin }}{{ path }}?provider={{ provider }}&embed=true">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/video.js/{{ videojs_version }}/video-js.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@silvermine/videojs-chromecast@{{ chromecast_version }}/dist/silvermine-videojs-chromecast.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/video.js/{{ videojs_version }}/video.min.js"></script>

View File

@ -72,7 +72,7 @@ if icecast_server is not None and stream_server is not None:
template_html = None
template_js = None
template_embed = tornado.template.Template('<iframe src="{{ origin }}{{ path }}?provider={{ provider }}&render=true"></iframe>')
template_embed = tornado.template.Template('<iframe src="{{ origin }}?provider={{ provider }}&render=true"></iframe>')
videojs_version = None
castjs_version = None
@ -174,21 +174,26 @@ class MainHandler(tornado.web.RequestHandler):
def handle_render(self, provider):
if template_js is not None and template_html is not None:
stream_path = f'{self.request.path}?provider={provider}'
origin = self.request.path
if stream_path is not None:
origin = f'{stream_server}{self.request.path}'
stream_path = f'{stream_server}{self.request.path}?provider={provider}'
rendered_js = template_js.generate(stream=stream_path);
b64_js = str(base64.b64encode(rendered_js), "ascii")
script = f'data:text/javascript;charset=utf-8;base64,{b64_js}'
rendered_html = template_html.generate(script=script, videojs_version=videojs_version, chromecast_version=chromecast_version, custom_style=custom_style, provider=provider, path=self.request.path)
rendered_html = template_html.generate(script=script, videojs_version=videojs_version, chromecast_version=chromecast_version, custom_style=custom_style, provider=provider, origin=origin)
self.write(rendered_html)
else:
self.set_status(404)
self.write("HTML template missing.")
def handle_embed(self, provider):
origin = self.request.path
if stream_path is not None:
origin = f'{stream_server}{self.request.path}'
embed_json = {}
embed_json["version"] = "1.0"
embed_json["type"] = "video"
embed_json["html"] = f'<iframe src="{self.request.uri}"></iframe>'
embed_json["html"] = str(template_embed.generate(origin=stream_server, path=self.request.path, provider=provider), "utf-8")
embed_json["html"] = str(template_embed.generate(origin=origin, provider=provider), "utf-8")
self.set_header("Content-Type", "application/json+oembed; charset=utf-8")
self.write(json.dumps(embed_json))