From b5b729160447edd0c6007596bd737c64812e83f5 Mon Sep 17 00:00:00 2001 From: Roy Olav Purser Date: Tue, 25 May 2021 11:56:59 +0200 Subject: [PATCH] fix nextcloud video --- backend/stream.py | 51 +++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/backend/stream.py b/backend/stream.py index d38c4af..303b7b4 100755 --- a/backend/stream.py +++ b/backend/stream.py @@ -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,19 +224,12 @@ 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 + data = data_filtered except Exception as e: logger.info(e) return data @@ -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})')