use high res picture in meta
This commit is contained in:
parent
e942d73474
commit
007aafafd5
@ -119,10 +119,6 @@ class MetaParser(html.parser.HTMLParser):
|
||||
self.accepted_attrs.append("og:title")
|
||||
self.accepted_attrs.append("og:description")
|
||||
self.accepted_attrs.append("og:image")
|
||||
self.accepted_attrs.append("og:video:height")
|
||||
self.accepted_attrs.append("og:video:width")
|
||||
self.accepted_attrs.append("og:image:height")
|
||||
self.accepted_attrs.append("og:image:width")
|
||||
super().__init__()
|
||||
def handle_starttag(self, tag, attrs):
|
||||
if tag == "meta":
|
||||
@ -218,10 +214,6 @@ class UpstreamHandler():
|
||||
data_new["og:title"] = data_raw.get("title")
|
||||
data_new["og:description"] = data_raw.get("author_name")
|
||||
data_new["og:image"] = data_raw.get("thumbnail_url")
|
||||
data_new["og:video:height"] = data_raw.get("height")
|
||||
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 = {}
|
||||
for key in data_new:
|
||||
value = data_new.get(key)
|
||||
@ -229,6 +221,16 @@ class UpstreamHandler():
|
||||
data_filtered[key] = value
|
||||
data_filtered.update(parser.meta_data)
|
||||
data = data_filtered
|
||||
image = data.get("og:image")
|
||||
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
|
||||
if full_image != image:
|
||||
image_status = await session.head(full_image)
|
||||
if hasattr(image_status, "status") and (image_status.status < 400):
|
||||
data["og:image"] = full_image
|
||||
|
||||
except Exception as e:
|
||||
logger.info(e)
|
||||
return data
|
||||
@ -369,13 +371,6 @@ class MainHandler(tornado.web.RequestHandler):
|
||||
meta = await handler.meta()
|
||||
image = meta.get("og:image")
|
||||
if isinstance(image, str):
|
||||
if handler.provider == "youtube":
|
||||
full_image = re.sub(r'\/[a-zA-Z0-9]+\.([a-zA-Z0-9]+)$', r'/maxresdefault.\1', image)
|
||||
image_type = None
|
||||
if full_image != image:
|
||||
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)
|
||||
if isinstance(image, str):
|
||||
self.set_header("Custom-Poster", image)
|
||||
|
Loading…
Reference in New Issue
Block a user