fix nextcloud video
This commit is contained in:
parent
1693e9d334
commit
b5b7291604
@ -156,16 +156,11 @@ class UpstreamHandler():
|
||||
self.stream = True
|
||||
|
||||
path = handler.request.path
|
||||
if self.provider == "youtube":
|
||||
path = path.strip("/")
|
||||
if isinstance(stream_server, str):
|
||||
self.render_url = f'{stream_server}{handler.request.path}?provider={self.provider}&render=true'
|
||||
self.stream_url = f'{stream_server}{handler.request.path}?provider={self.provider}'
|
||||
else:
|
||||
self.render_url = f'{handler.request.path}?provider={self.provider}&render=true'
|
||||
self.stream_url = f'{handler.request.path}?provider={self.provider}'
|
||||
|
||||
src = providers[self.provider] + path
|
||||
|
||||
if self.provider == "nextcloud":
|
||||
src = src.removesuffix("/").removesuffix("download").removesuffix("/")
|
||||
|
||||
proxy_list = proxies.get(self.provider)
|
||||
if isinstance(proxy_list, list):
|
||||
futures = []
|
||||
@ -202,13 +197,23 @@ class UpstreamHandler():
|
||||
|
||||
async def meta(self):
|
||||
data = {}
|
||||
logger.info(type(self.proxy))
|
||||
try:
|
||||
embed_url = f'https://noembed.com/embed?url={self.upstream_safe}'
|
||||
async with self.proxy.session() as session:
|
||||
resp = await session.get(embed_url)
|
||||
text = await resp.text()
|
||||
data_raw = json.loads(text)
|
||||
resp_embed_future = session.get(embed_url)
|
||||
resp_upstream_future = session.get(self.upstream)
|
||||
resp_embed = await resp_embed_future
|
||||
resp_upstream = await resp_upstream_future
|
||||
text_embed_future = resp_embed.text()
|
||||
text_upstream_future = resp_upstream.text()
|
||||
text_embed = await text_embed_future
|
||||
text_upstream = await text_upstream_future
|
||||
|
||||
parser = MetaParser()
|
||||
parser.feed(text_upstream)
|
||||
data_upstream = parser.meta_data
|
||||
|
||||
data_raw = json.loads(text_embed)
|
||||
if isinstance(data_raw, dict):
|
||||
data_new = {}
|
||||
data_valid = True
|
||||
@ -219,18 +224,11 @@ class UpstreamHandler():
|
||||
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")
|
||||
data_filtered = {}
|
||||
data_filtered = data_upstream
|
||||
for key in data_new:
|
||||
value = data_new.get(key)
|
||||
if isinstance(value, str):
|
||||
data_filtered[key] = value
|
||||
if len(data_filtered) == 0:
|
||||
resp = await session.get(self.upstream)
|
||||
text = await resp.text()
|
||||
parser = MetaParser()
|
||||
parser.feed(text)
|
||||
data = parser.meta_data
|
||||
else:
|
||||
data = data_filtered
|
||||
except Exception as e:
|
||||
logger.info(e)
|
||||
@ -365,7 +363,9 @@ class MainHandler(tornado.web.RequestHandler):
|
||||
self.write("HTML template missing.")
|
||||
|
||||
async def handle_stream(self, handler, redir):
|
||||
if handler.provider != "nextcloud":
|
||||
if handler.provider == "nextcloud":
|
||||
upstream = handler.upstream + "/download"
|
||||
else:
|
||||
meta = await handler.meta()
|
||||
image = meta.get("og:image")
|
||||
if isinstance(image, str):
|
||||
@ -374,11 +374,6 @@ class MainHandler(tornado.web.RequestHandler):
|
||||
image = await handler.proxy.proxy_url(image, None)
|
||||
if isinstance(image, str):
|
||||
self.set_header("Custom-Poster", image)
|
||||
|
||||
upstream = None
|
||||
if handler.provider == "nextcloud":
|
||||
upstream = urllib.parse.urljoin(handler.upstream, "/download")
|
||||
else:
|
||||
upstream = await stream_providers.get_any(handler.upstream, handler.proxy, logger)
|
||||
if upstream is None:
|
||||
logger.info(f'invalid upstream ({handler.provider})')
|
||||
|
Loading…
Reference in New Issue
Block a user