separate embed endpoint
This commit is contained in:
parent
8ed4aafc64
commit
432b67eb4a
@ -1,7 +1,7 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link type="application/json+oembed" href="{{ oembed }}" />
|
||||
<link type="application/json+oembed" href="{{ 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>
|
||||
|
30
stream.py
30
stream.py
@ -72,6 +72,8 @@ 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="{{ path }}?provider={{ provider }}&render=true"></iframe>')
|
||||
|
||||
videojs_version = None
|
||||
castjs_version = None
|
||||
custom_style = None
|
||||
@ -155,13 +157,13 @@ def rewrite(current, provider, proxy):
|
||||
class MainHandler(tornado.web.RequestHandler):
|
||||
def handle_any(self, write):
|
||||
provider = self.get_query_argument("provider", None)
|
||||
render = self.get_query_argument("render", False)
|
||||
render = self.get_query_argument("render", "false")
|
||||
embed = self.get_query_argument("embed", "false")
|
||||
if isinstance(provider, str):
|
||||
if isinstance(render, str):
|
||||
if render.lower() == "true":
|
||||
self.handle_render(provider, write)
|
||||
else:
|
||||
self.handle_stream(provider, write)
|
||||
self.handle_render(provider)
|
||||
elif embed.lower() == "true":
|
||||
self.handle_embed(provider)
|
||||
else:
|
||||
self.handle_stream(provider, write)
|
||||
else:
|
||||
@ -170,23 +172,25 @@ class MainHandler(tornado.web.RequestHandler):
|
||||
if write:
|
||||
self.write("Stream not found. (provider missing)")
|
||||
|
||||
def handle_render(self, provider, write):
|
||||
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}'
|
||||
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}'
|
||||
embed_json = {}
|
||||
embed_json["version"] = "1.0"
|
||||
embed_json["type"] = "video"
|
||||
embed_json["html"] = f'<iframe src="{self.request.uri}"></iframe>'
|
||||
b64_frame = str(base64.b64encode(bytes(json.dumps(embed_json), "utf-8")), "ascii")
|
||||
oembed = f'data:application/json+oembed;charset=utf-8;base64,{b64_frame}'
|
||||
rendered_html = template_html.generate(script=script, videojs_version=videojs_version, chromecast_version=chromecast_version, custom_style=custom_style, oembed=oembed)
|
||||
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)
|
||||
self.write(rendered_html)
|
||||
else:
|
||||
self.set_status(404)
|
||||
self.write("HTML template missing.")
|
||||
def handle_embed(self, provider):
|
||||
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(path=self.request.path, provider=provider), "utf-8")
|
||||
self.set_header("Content-Type", "application/json+oembed; charset=utf-8")
|
||||
self.write(json.dumps(embed_json))
|
||||
|
||||
def handle_stream(self, provider, write):
|
||||
upstream = None
|
||||
|
Loading…
Reference in New Issue
Block a user