load thumbnail
This commit is contained in:
parent
358693035b
commit
d418b429aa
@ -146,14 +146,16 @@ 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")
|
||||||
self.render = False
|
poster_str = handler.get_query_argument("poster", "false")
|
||||||
self.stream = 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
|
||||||
|
|
||||||
@ -203,7 +205,7 @@ class UpstreamHandler():
|
|||||||
await session.close()
|
await session.close()
|
||||||
|
|
||||||
async def meta(self):
|
async 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}'
|
||||||
async with self.proxy.session() as session:
|
async with self.proxy.session() as session:
|
||||||
@ -230,12 +232,14 @@ class UpstreamHandler():
|
|||||||
text = await resp.text()
|
text = await resp.text()
|
||||||
parser = MetaParser()
|
parser = MetaParser()
|
||||||
parser.feed(text)
|
parser.feed(text)
|
||||||
data_filtered = parser.meta_data
|
data = parser.meta_data
|
||||||
data = list(data_filtered.items())
|
data = data_filtered
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.info(e)
|
logger.info(e)
|
||||||
logger.info(data)
|
|
||||||
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:
|
||||||
@ -344,6 +348,8 @@ 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)
|
||||||
@ -351,13 +357,14 @@ 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()
|
meta = await handler.meta_list()
|
||||||
title = handler.render_url
|
title = handler.render_url
|
||||||
video_title = None
|
video_title = None
|
||||||
for elem in meta:
|
for elem in meta:
|
||||||
if isinstance(elem[1], str):
|
if isinstance(elem[1], str):
|
||||||
if elem[0] == "og:title":
|
if elem[0] == "og:title":
|
||||||
video_title = elem[1]
|
video_title = elem[1]
|
||||||
|
break
|
||||||
|
|
||||||
data["script"] = script_file
|
data["script"] = script_file
|
||||||
data["videojs_version"] = videojs_version
|
data["videojs_version"] = videojs_version
|
||||||
@ -370,6 +377,17 @@ 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):
|
||||||
|
meta = await handler.meta()
|
||||||
|
image = meta.get("og:image")
|
||||||
|
if isinstance(image, str):
|
||||||
|
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")
|
||||||
|
|
||||||
async def handle_stream(self, handler, redir):
|
async def handle_stream(self, handler, redir):
|
||||||
upstream = None
|
upstream = None
|
||||||
if handler.provider == "nextcloud":
|
if handler.provider == "nextcloud":
|
||||||
|
@ -69,22 +69,14 @@ class YoutubeRunner(StreamProvider):
|
|||||||
return await asyncio.to_thread(self.stream)
|
return await asyncio.to_thread(self.stream)
|
||||||
|
|
||||||
async def get_ytdl(upstream, proxy, logger):
|
async def get_ytdl(upstream, proxy, logger):
|
||||||
url = None
|
runner = YoutubeRunner(upstream, proxy)
|
||||||
try:
|
result = await runner.run()
|
||||||
runner = YoutubeRunner(upstream, proxy)
|
return result
|
||||||
url = await runner.run()
|
|
||||||
except Exception as e:
|
|
||||||
logger.info(e)
|
|
||||||
return url
|
|
||||||
|
|
||||||
async def get_streamlink(upstream, proxy, logger):
|
async def get_streamlink(upstream, proxy, logger):
|
||||||
url = None
|
runner = StreamlinkRunner(upstream, proxy)
|
||||||
try:
|
result = await runner.run()
|
||||||
runner = StreamlinkRunner(upstream, proxy)
|
return result
|
||||||
url = await runner.run()
|
|
||||||
except Exception as e:
|
|
||||||
logger.info(e)
|
|
||||||
return url
|
|
||||||
|
|
||||||
async def get_any(upstream, proxy, logger):
|
async def get_any(upstream, proxy, logger):
|
||||||
tasks = []
|
tasks = []
|
||||||
@ -92,9 +84,12 @@ async def get_any(upstream, proxy, logger):
|
|||||||
tasks.append(asyncio.create_task(get_ytdl(upstream, proxy, logger)))
|
tasks.append(asyncio.create_task(get_ytdl(upstream, proxy, logger)))
|
||||||
result = None
|
result = None
|
||||||
for task in asyncio.as_completed(tasks, timeout=5.0):
|
for task in asyncio.as_completed(tasks, timeout=5.0):
|
||||||
result = await task
|
try:
|
||||||
if isinstance(result, str):
|
result = await task
|
||||||
break
|
if isinstance(result, str):
|
||||||
|
break
|
||||||
|
except Exception as e:
|
||||||
|
logger.info(e)
|
||||||
for task in tasks:
|
for task in tasks:
|
||||||
if not task.done():
|
if not task.done():
|
||||||
task.cancel()
|
task.cancel()
|
||||||
|
@ -1,14 +1,24 @@
|
|||||||
(() => {
|
(() => {
|
||||||
const findUpstream = () => {
|
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);
|
||||||
|
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);
|
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 upstream = findUpstream();
|
const upstream = findUpstreamVideo();
|
||||||
const xhr = new XMLHttpRequest();
|
const xhr = new XMLHttpRequest();
|
||||||
xhr.open("HEAD", upstream, true);
|
xhr.open("HEAD", upstream, true);
|
||||||
xhr.send();
|
xhr.send();
|
||||||
@ -37,6 +47,7 @@
|
|||||||
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);
|
||||||
|
player.poster(findUpstreamPoster());
|
||||||
const source = {};
|
const source = {};
|
||||||
source.type = ctype;
|
source.type = ctype;
|
||||||
source.src = upstream;
|
source.src = upstream;
|
||||||
|
Loading…
Reference in New Issue
Block a user