meta template

This commit is contained in:
Roy Olav Purser 2021-05-14 12:54:53 +02:00
parent b74791aafa
commit 77ab3e38df
Signed by: roypur
GPG Key ID: E14D26A036F21656
3 changed files with 41 additions and 36 deletions

View File

@ -1,17 +1,7 @@
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta property="og:title" content="{{ data["og:title"] }}" />
<meta property="og:description" content="{{ data["og:description"] }}" />
<meta property="og:type" content="video.other" />
<meta property="og:image" content="{{ data["og:image"] }}" />
<meta property="og:image:height" content="{{ data["og:image:height"] }}" />
<meta property="og:image:width" content="{{ data["og:image:width"] }}" />
<meta property="og:url" content="{% raw data["render_url"] %}" />
<meta property="og:video:url" content="{% raw data["render_url"] %}" />
<meta property="og:video:secure_url" content="{% raw data["stream_url"] %}" />
<meta property="og:video:height" content="{{ data["og:video:height"] }}" />
<meta property="og:video:width" content="{{ data["og:video:width"] }}" />
<meta name="viewport" content="width=device-width, initial-scale=1">{% for item in meta %}
{% block item %}<meta property="{{ item[0] }}" content="{{ item[1] }}" />{% end %}{% end %}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/video.js/{{ data["videojs_version"] }}/video-js.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@silvermine/videojs-chromecast@{{ data["chromecast_version"] }}/dist/silvermine-videojs-chromecast.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/video.js/{{ data["videojs_version"] }}/video.min.js"></script>

View File

@ -1,12 +1,21 @@
let url = new URL("{{ stream }}", window.location.origin);
let upstream = url.href;
(() => {
let url = new URL("{{ stream }}", window.location.origin);
let upstream = url.href;
document.addEventListener("DOMContentLoaded", () => {
let xhr = new XMLHttpRequest();
xhr.open("HEAD", upstream, true);
xhr.send();
let count = 2;
let handleCount = () => {
if(--count === 0) {
handle();
}
}
let handle = () => {
let bodies = document.getElementsByTagName("body");
if(bodies.length === 1) {
let body = bodies[0];
let xhr = new XMLHttpRequest();
xhr.addEventListener("load", () => {
let video = document.createElement("video");
video.className = "video-js vjs-big-play-centered";
body.appendChild(video);
@ -25,8 +34,9 @@ document.addEventListener("DOMContentLoaded", () => {
source.type = ctype;
source.src = upstream;
player.src(source);
});
xhr.open("HEAD", upstream, true);
xhr.send();
}
});
}
document.addEventListener("DOMContentLoaded", handleCount);
xhr.addEventListener("load", handleCount);
})();

View File

@ -106,14 +106,28 @@ class UpstreamHandler():
proxies[provider] = current_list
return
def meta(self):
data = {}
data = []
try:
embed_url = f'https://noembed.com/embed?url={self.upstream_safe}'
logger.info(embed_url)
resp = requests.get(embed_url)
data_raw = json.loads(resp.text)
if isinstance(data_raw, dict):
data = data_raw
data_new = {}
data_valid = True
data_new["og:title"] = data_raw.get("title")
data_new["og:description"] = data_raw.get("author_name")
data_new["og:image"] = data_raw.get("thumbnail_url")
data_new["og:video:height"] = data_raw.get("height")
data_new["og:video:width"] = data_raw.get("width")
data_new["og:image:height"] = data_raw.get("thumbnail_height")
data_new["og:image:width"] = data_raw.get("thumbnail_width")
for elem in data_new:
if not isinstance(elem, str):
data_valid = False
break
if data_valid:
data = list(data_new.items())
except Exception as e:
logger.info(e)
return data
@ -237,22 +251,13 @@ class MainHandler(tornado.web.RequestHandler):
b64_js = str(base64.b64encode(rendered_js), "ascii")
script = f'data:text/javascript;charset=utf-8;base64,{b64_js}'
meta = handler.meta()
data = {}
if meta is not None:
data["og:title"] = meta.get("title", "")
data["og:description"] = meta.get("author_name", "")
data["og:image"] = meta.get("thumbnail_url", "")
data["og:video:height"] = meta.get("height", "180")
data["og:video:width"] = meta.get("width", "320")
data["og:image:height"] = meta.get("thumbnail_height", "180")
data["og:image:width"] = meta.get("thumbnail_width", "320")
data["script"] = script
data["videojs_version"] = videojs_version
data["chromecast_version"] = chromecast_version
data["custom_style"] = custom_style
data["stream_url"] = handler.stream_url
data["render_url"] = handler.render_url
rendered_html = template_html.generate(data=data)
rendered_html = template_html.generate(data=data, meta=meta)
self.write(rendered_html)
else:
self.set_status(404)