add poster image header

This commit is contained in:
Roy Olav Purser 2021-05-25 10:22:22 +02:00
parent dc164fd377
commit ff181da10f
Signed by: roypur
GPG Key ID: E14D26A036F21656
2 changed files with 11 additions and 43 deletions

View File

@ -146,16 +146,12 @@ class UpstreamHandler():
self.upstream_safe = None
self.render = False
self.stream = False
self.poster = False
async def setup(self, handler):
self.provider = handler.get_query_argument("provider", None)
render_str = handler.get_query_argument("render", "false")
poster_str = handler.get_query_argument("poster", "false")
if self.provider in providers.keys():
if render_str.lower() == "true":
self.render = True
elif poster_str.lower() == "true":
self.poster = True
else:
self.stream = True
@ -237,9 +233,6 @@ class UpstreamHandler():
except Exception as e:
logger.info(e)
return data
async def meta_list(self):
meta_data = await self.meta()
return list(meta_data.items())
if icecast_server is not None and stream_server is not None:
try:
@ -348,8 +341,6 @@ class MainHandler(tornado.web.RequestHandler):
await self.handle_render(handler)
elif handler.stream:
await self.handle_stream(handler, redir)
elif handler.poster:
await self.handle_poster(handler)
else:
logger.info(f'provider missing {self.request.uri}')
self.set_status(404)
@ -357,15 +348,10 @@ class MainHandler(tornado.web.RequestHandler):
async def handle_render(self, handler):
if script_file is not None and template_html is not None:
meta = await handler.meta_list()
meta = await handler.meta()
meta_list = list(meta.items())
title = handler.render_url
video_title = None
for elem in meta:
if isinstance(elem[1], str):
if elem[0] == "og:title":
video_title = elem[1]
break
video_title = meta.get("og:title")
data["script"] = script_file
data["videojs_version"] = videojs_version
data["chromecast_version"] = chromecast_version
@ -377,20 +363,16 @@ class MainHandler(tornado.web.RequestHandler):
self.set_status(404)
self.write("HTML template missing.")
async def handle_poster(self, handler):
async def handle_stream(self, handler, redir):
meta = await handler.meta()
image = meta.get("og:image")
if isinstance(image, str):
if handler.provider == "youtube":
if handler.provider == "youtube" and image.endswith("hqdefault.jpg"):
image = image.removesuffix("hqdefault.jpg") + "maxresdefault.jpg"
url = await handler.proxy.proxy_url(image, None)
if isinstance(url, str):
self.redirect(url, status=303)
return
self.set_status(404)
self.write("Poster not found")
image = await handler.proxy.proxy_url(image, None)
if isinstance(image, str):
self.set_header("Custom-Poster", image)
async def handle_stream(self, handler, redir):
upstream = None
if handler.provider == "nextcloud":
upstream = handler.upstream

View File

@ -2,26 +2,11 @@
const findUpstreamVideo = () => {
const search = new URLSearchParams(location.search);
search.set("render", "false");
search.set("poster", "false");
const url = new URL(location.origin);
url.pathname = location.pathname;
url.search = search.toString();
return url.href;
}
const findUpstreamPoster = () => {
const search = new URLSearchParams(location.search);
search.set("render", "false");
search.set("poster", "true");
const url = new URL(location.origin);
url.pathname = location.pathname;
url.search = search.toString();
return url.href;
}
const getProvider = () => {
const search = new URLSearchParams(location.search);
return search.get("provider");
}
const upstream = findUpstreamVideo();
const xhr = new XMLHttpRequest();
@ -41,6 +26,7 @@
video.className = "video-js vjs-big-play-centered";
body.appendChild(video);
const ctype = xhr.getResponseHeader("Content-Type");
const image = xhr.getResponseHeader("Custom-Poster");
console.log(ctype);
const options = {};
options.controls = true;
@ -52,8 +38,8 @@
options.plugins.chromecast = {};
options.plugins.chromecast.addButtonToControlBar = false;
const player = videojs(video, options);
if(getProvider() !== "nextcloud") {
player.poster(findUpstreamPoster());
if((image instanceof String) || ((typeof image) == "string")) {
player.poster(image);
}
const source = {};
source.type = ctype;