verify youtube thumbnail size

This commit is contained in:
Roy Olav Purser 2021-05-25 13:00:19 +02:00
parent 1647f35df1
commit 51530c2a6b
Signed by: roypur
GPG Key ID: E14D26A036F21656

View File

@ -209,11 +209,8 @@ class UpstreamHandler():
text_upstream_future = resp_upstream.text() text_upstream_future = resp_upstream.text()
text_embed = await text_embed_future text_embed = await text_embed_future
text_upstream = await text_upstream_future text_upstream = await text_upstream_future
parser = MetaParser() parser = MetaParser()
parser.feed(text_upstream) parser.feed(text_upstream)
data_upstream = parser.meta_data
data_raw = json.loads(text_embed) data_raw = json.loads(text_embed)
if isinstance(data_raw, dict): if isinstance(data_raw, dict):
data_new = {} data_new = {}
@ -225,11 +222,12 @@ 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_upstream data_filtered = {}
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
data_filtered.update(parser.meta_data)
data = data_filtered data = data_filtered
except Exception as e: except Exception as e:
logger.info(e) logger.info(e)
@ -367,11 +365,21 @@ class MainHandler(tornado.web.RequestHandler):
if handler.provider == "nextcloud": if handler.provider == "nextcloud":
upstream = handler.upstream + "/download" upstream = handler.upstream + "/download"
else: else:
if not 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" and image.endswith("hqdefault.jpg"): if handler.provider == "youtube":
image = image.removesuffix("hqdefault.jpg") + "maxresdefault.jpg" full_image = None
image_type = None
if image.endswith("hqdefault.jpg"):
full_image = image.removesuffix("hqdefault.jpg") + "maxresdefault.jpg"
elif image.endswith("hqdefault.webp"):
full_image = image.removesuffix("hqdefault.webp") + "maxresdefault.webp"
if isinstance(full_image, str):
image_type = await handler.proxy.content_type(full_image)
if isinstance(image_type, str) and image_type.startswith("image"):
image = full_image
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)