add sddefault image

This commit is contained in:
Roy Olav Purser 2021-05-26 20:09:35 +02:00
parent 0588fb301c
commit 755d198743
Signed by: roypur
GPG Key ID: E14D26A036F21656

View File

@ -225,12 +225,23 @@ class UpstreamHandler():
if isinstance(image, str):
if self.provider == "youtube":
full_image = re.sub(r'\/[a-zA-Z0-9]+\.([a-zA-Z0-9]+)$', r'/maxresdefault.\1', image)
image_status = None
standard_image = re.sub(r'\/[a-zA-Z0-9]+\.([a-zA-Z0-9]+)$', r'/sddefault.\1', image)
image_status_standard_future = None
image_status_full_future = None
if full_image != image:
image_status = await session.head(full_image)
if hasattr(image_status, "status") and (image_status.status < 400):
image_status_full_future = session.head(full_image)
if full_image != image:
image_status_standard_future = session.head(standard_image)
image_status_full = None
image_status_standard = None
if image_status_standard_future != None:
image_status_standard = await image_status_standard_future
if image_status_full_future != None:
image_status_full = await image_status_full_future
if hasattr(image_status_full, "status") and (image_status_full.status < 400):
data["og:image"] = full_image
elif hasattr(image_status_standard, "status") and (image_status_standard.status < 400):
data["og:image"] = standard_image
except Exception as e:
logger.info(e)
return data