image size regex

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

View File

@ -370,13 +370,9 @@ class MainHandler(tornado.web.RequestHandler):
image = meta.get("og:image") image = meta.get("og:image")
if isinstance(image, str): if isinstance(image, str):
if handler.provider == "youtube": if handler.provider == "youtube":
full_image = None full_image = re.sub(r'\/[a-zA-Z0-9]+\.([a-zA-Z0-9]+)$', r'/maxresdefault.\1', image)
image_type = None image_type = None
if image.endswith("hqdefault.jpg"): if full_image != image:
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) image_type = await handler.proxy.content_type(full_image)
if isinstance(image_type, str) and image_type.startswith("image"): if isinstance(image_type, str) and image_type.startswith("image"):
image = full_image image = full_image