fix nextcloud video

This commit is contained in:
Roy Olav Purser 2021-05-25 11:56:59 +02:00
parent 1693e9d334
commit b5b7291604
Signed by: roypur
GPG Key ID: E14D26A036F21656

View File

@ -156,16 +156,11 @@ class UpstreamHandler():
self.stream = True self.stream = True
path = handler.request.path 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 src = providers[self.provider] + path
if self.provider == "nextcloud":
src = src.removesuffix("/").removesuffix("download").removesuffix("/")
proxy_list = proxies.get(self.provider) proxy_list = proxies.get(self.provider)
if isinstance(proxy_list, list): if isinstance(proxy_list, list):
futures = [] futures = []
@ -202,13 +197,23 @@ class UpstreamHandler():
async def meta(self): async def meta(self):
data = {} data = {}
logger.info(type(self.proxy))
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:
resp = await session.get(embed_url) resp_embed_future = session.get(embed_url)
text = await resp.text() resp_upstream_future = session.get(self.upstream)
data_raw = json.loads(text) 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): if isinstance(data_raw, dict):
data_new = {} data_new = {}
data_valid = True data_valid = True
@ -219,18 +224,11 @@ class UpstreamHandler():
data_new["og:video:width"] = data_raw.get("width") data_new["og:video:width"] = data_raw.get("width")
data_new["og:image:height"] = data_raw.get("thumbnail_height") data_new["og:image:height"] = data_raw.get("thumbnail_height")
data_new["og:image:width"] = data_raw.get("thumbnail_width") data_new["og:image:width"] = data_raw.get("thumbnail_width")
data_filtered = {} data_filtered = data_upstream
for key in data_new: for key in data_new:
value = data_new.get(key) value = data_new.get(key)
if isinstance(value, str): if isinstance(value, str):
data_filtered[key] = value 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 data = data_filtered
except Exception as e: except Exception as e:
logger.info(e) logger.info(e)
@ -365,7 +363,9 @@ class MainHandler(tornado.web.RequestHandler):
self.write("HTML template missing.") self.write("HTML template missing.")
async def handle_stream(self, handler, redir): async def handle_stream(self, handler, redir):
if handler.provider != "nextcloud": if handler.provider == "nextcloud":
upstream = handler.upstream + "/download"
else:
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):
@ -374,11 +374,6 @@ class MainHandler(tornado.web.RequestHandler):
image = await handler.proxy.proxy_url(image, None) image = await handler.proxy.proxy_url(image, None)
if isinstance(image, str): if isinstance(image, str):
self.set_header("Custom-Poster", image) 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) upstream = await stream_providers.get_any(handler.upstream, handler.proxy, logger)
if upstream is None: if upstream is None:
logger.info(f'invalid upstream ({handler.provider})') logger.info(f'invalid upstream ({handler.provider})')