add poster image header
This commit is contained in:
parent
dc164fd377
commit
ff181da10f
@ -146,16 +146,12 @@ class UpstreamHandler():
|
|||||||
self.upstream_safe = None
|
self.upstream_safe = None
|
||||||
self.render = False
|
self.render = False
|
||||||
self.stream = False
|
self.stream = False
|
||||||
self.poster = False
|
|
||||||
async def setup(self, handler):
|
async def setup(self, handler):
|
||||||
self.provider = handler.get_query_argument("provider", None)
|
self.provider = handler.get_query_argument("provider", None)
|
||||||
render_str = handler.get_query_argument("render", "false")
|
render_str = handler.get_query_argument("render", "false")
|
||||||
poster_str = handler.get_query_argument("poster", "false")
|
|
||||||
if self.provider in providers.keys():
|
if self.provider in providers.keys():
|
||||||
if render_str.lower() == "true":
|
if render_str.lower() == "true":
|
||||||
self.render = True
|
self.render = True
|
||||||
elif poster_str.lower() == "true":
|
|
||||||
self.poster = True
|
|
||||||
else:
|
else:
|
||||||
self.stream = True
|
self.stream = True
|
||||||
|
|
||||||
@ -237,9 +233,6 @@ class UpstreamHandler():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.info(e)
|
logger.info(e)
|
||||||
return data
|
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:
|
if icecast_server is not None and stream_server is not None:
|
||||||
try:
|
try:
|
||||||
@ -348,8 +341,6 @@ class MainHandler(tornado.web.RequestHandler):
|
|||||||
await self.handle_render(handler)
|
await self.handle_render(handler)
|
||||||
elif handler.stream:
|
elif handler.stream:
|
||||||
await self.handle_stream(handler, redir)
|
await self.handle_stream(handler, redir)
|
||||||
elif handler.poster:
|
|
||||||
await self.handle_poster(handler)
|
|
||||||
else:
|
else:
|
||||||
logger.info(f'provider missing {self.request.uri}')
|
logger.info(f'provider missing {self.request.uri}')
|
||||||
self.set_status(404)
|
self.set_status(404)
|
||||||
@ -357,15 +348,10 @@ class MainHandler(tornado.web.RequestHandler):
|
|||||||
|
|
||||||
async def handle_render(self, handler):
|
async def handle_render(self, handler):
|
||||||
if script_file is not None and template_html is not None:
|
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
|
title = handler.render_url
|
||||||
video_title = None
|
video_title = meta.get("og:title")
|
||||||
for elem in meta:
|
|
||||||
if isinstance(elem[1], str):
|
|
||||||
if elem[0] == "og:title":
|
|
||||||
video_title = elem[1]
|
|
||||||
break
|
|
||||||
|
|
||||||
data["script"] = script_file
|
data["script"] = script_file
|
||||||
data["videojs_version"] = videojs_version
|
data["videojs_version"] = videojs_version
|
||||||
data["chromecast_version"] = chromecast_version
|
data["chromecast_version"] = chromecast_version
|
||||||
@ -377,20 +363,16 @@ class MainHandler(tornado.web.RequestHandler):
|
|||||||
self.set_status(404)
|
self.set_status(404)
|
||||||
self.write("HTML template missing.")
|
self.write("HTML template missing.")
|
||||||
|
|
||||||
async def handle_poster(self, handler):
|
async def handle_stream(self, handler, redir):
|
||||||
meta = await handler.meta()
|
meta = await handler.meta()
|
||||||
image = meta.get("og:image")
|
image = meta.get("og:image")
|
||||||
if isinstance(image, str):
|
if isinstance(image, str):
|
||||||
if handler.provider == "youtube":
|
if handler.provider == "youtube" and image.endswith("hqdefault.jpg"):
|
||||||
image = image.removesuffix("hqdefault.jpg") + "maxresdefault.jpg"
|
image = image.removesuffix("hqdefault.jpg") + "maxresdefault.jpg"
|
||||||
url = await handler.proxy.proxy_url(image, None)
|
image = await handler.proxy.proxy_url(image, None)
|
||||||
if isinstance(url, str):
|
if isinstance(image, str):
|
||||||
self.redirect(url, status=303)
|
self.set_header("Custom-Poster", image)
|
||||||
return
|
|
||||||
self.set_status(404)
|
|
||||||
self.write("Poster not found")
|
|
||||||
|
|
||||||
async def handle_stream(self, handler, redir):
|
|
||||||
upstream = None
|
upstream = None
|
||||||
if handler.provider == "nextcloud":
|
if handler.provider == "nextcloud":
|
||||||
upstream = handler.upstream
|
upstream = handler.upstream
|
||||||
|
@ -2,26 +2,11 @@
|
|||||||
const findUpstreamVideo = () => {
|
const findUpstreamVideo = () => {
|
||||||
const search = new URLSearchParams(location.search);
|
const search = new URLSearchParams(location.search);
|
||||||
search.set("render", "false");
|
search.set("render", "false");
|
||||||
search.set("poster", "false");
|
|
||||||
const url = new URL(location.origin);
|
const url = new URL(location.origin);
|
||||||
url.pathname = location.pathname;
|
url.pathname = location.pathname;
|
||||||
url.search = search.toString();
|
url.search = search.toString();
|
||||||
return url.href;
|
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 upstream = findUpstreamVideo();
|
||||||
const xhr = new XMLHttpRequest();
|
const xhr = new XMLHttpRequest();
|
||||||
@ -41,6 +26,7 @@
|
|||||||
video.className = "video-js vjs-big-play-centered";
|
video.className = "video-js vjs-big-play-centered";
|
||||||
body.appendChild(video);
|
body.appendChild(video);
|
||||||
const ctype = xhr.getResponseHeader("Content-Type");
|
const ctype = xhr.getResponseHeader("Content-Type");
|
||||||
|
const image = xhr.getResponseHeader("Custom-Poster");
|
||||||
console.log(ctype);
|
console.log(ctype);
|
||||||
const options = {};
|
const options = {};
|
||||||
options.controls = true;
|
options.controls = true;
|
||||||
@ -52,8 +38,8 @@
|
|||||||
options.plugins.chromecast = {};
|
options.plugins.chromecast = {};
|
||||||
options.plugins.chromecast.addButtonToControlBar = false;
|
options.plugins.chromecast.addButtonToControlBar = false;
|
||||||
const player = videojs(video, options);
|
const player = videojs(video, options);
|
||||||
if(getProvider() !== "nextcloud") {
|
if((image instanceof String) || ((typeof image) == "string")) {
|
||||||
player.poster(findUpstreamPoster());
|
player.poster(image);
|
||||||
}
|
}
|
||||||
const source = {};
|
const source = {};
|
||||||
source.type = ctype;
|
source.type = ctype;
|
||||||
|
Loading…
Reference in New Issue
Block a user