meta template
This commit is contained in:
parent
b74791aafa
commit
77ab3e38df
@ -1,17 +1,7 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">{% for item in meta %}
|
||||||
<meta property="og:title" content="{{ data["og:title"] }}" />
|
{% block item %}<meta property="{{ item[0] }}" content="{{ item[1] }}" />{% end %}{% end %}
|
||||||
<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"] }}" />
|
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/video.js/{{ data["videojs_version"] }}/video-js.css">
|
<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">
|
<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>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/video.js/{{ data["videojs_version"] }}/video.min.js"></script>
|
||||||
|
@ -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();
|
||||||
let bodies = document.getElementsByTagName("body");
|
xhr.open("HEAD", upstream, true);
|
||||||
if(bodies.length === 1) {
|
xhr.send();
|
||||||
let body = bodies[0];
|
|
||||||
let xhr = new XMLHttpRequest();
|
let count = 2;
|
||||||
xhr.addEventListener("load", () => {
|
let handleCount = () => {
|
||||||
|
if(--count === 0) {
|
||||||
|
handle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let handle = () => {
|
||||||
|
let bodies = document.getElementsByTagName("body");
|
||||||
|
if(bodies.length === 1) {
|
||||||
let video = document.createElement("video");
|
let video = document.createElement("video");
|
||||||
video.className = "video-js vjs-big-play-centered";
|
video.className = "video-js vjs-big-play-centered";
|
||||||
body.appendChild(video);
|
body.appendChild(video);
|
||||||
@ -25,8 +34,9 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
source.type = ctype;
|
source.type = ctype;
|
||||||
source.src = upstream;
|
source.src = upstream;
|
||||||
player.src(source);
|
player.src(source);
|
||||||
});
|
}
|
||||||
xhr.open("HEAD", upstream, true);
|
|
||||||
xhr.send();
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
document.addEventListener("DOMContentLoaded", handleCount);
|
||||||
|
xhr.addEventListener("load", handleCount);
|
||||||
|
})();
|
||||||
|
29
stream.py
29
stream.py
@ -106,14 +106,28 @@ class UpstreamHandler():
|
|||||||
proxies[provider] = current_list
|
proxies[provider] = current_list
|
||||||
return
|
return
|
||||||
def meta(self):
|
def meta(self):
|
||||||
data = {}
|
data = []
|
||||||
try:
|
try:
|
||||||
embed_url = f'https://noembed.com/embed?url={self.upstream_safe}'
|
embed_url = f'https://noembed.com/embed?url={self.upstream_safe}'
|
||||||
logger.info(embed_url)
|
logger.info(embed_url)
|
||||||
resp = requests.get(embed_url)
|
resp = requests.get(embed_url)
|
||||||
data_raw = json.loads(resp.text)
|
data_raw = json.loads(resp.text)
|
||||||
if isinstance(data_raw, dict):
|
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:
|
except Exception as e:
|
||||||
logger.info(e)
|
logger.info(e)
|
||||||
return data
|
return data
|
||||||
@ -237,22 +251,13 @@ class MainHandler(tornado.web.RequestHandler):
|
|||||||
b64_js = str(base64.b64encode(rendered_js), "ascii")
|
b64_js = str(base64.b64encode(rendered_js), "ascii")
|
||||||
script = f'data:text/javascript;charset=utf-8;base64,{b64_js}'
|
script = f'data:text/javascript;charset=utf-8;base64,{b64_js}'
|
||||||
meta = handler.meta()
|
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["script"] = script
|
||||||
data["videojs_version"] = videojs_version
|
data["videojs_version"] = videojs_version
|
||||||
data["chromecast_version"] = chromecast_version
|
data["chromecast_version"] = chromecast_version
|
||||||
data["custom_style"] = custom_style
|
data["custom_style"] = custom_style
|
||||||
data["stream_url"] = handler.stream_url
|
data["stream_url"] = handler.stream_url
|
||||||
data["render_url"] = handler.render_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)
|
self.write(rendered_html)
|
||||||
else:
|
else:
|
||||||
self.set_status(404)
|
self.set_status(404)
|
||||||
|
Loading…
Reference in New Issue
Block a user