verify youtube thumbnail size
This commit is contained in:
parent
1647f35df1
commit
51530c2a6b
@ -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,14 +365,24 @@ class MainHandler(tornado.web.RequestHandler):
|
|||||||
if handler.provider == "nextcloud":
|
if handler.provider == "nextcloud":
|
||||||
upstream = handler.upstream + "/download"
|
upstream = handler.upstream + "/download"
|
||||||
else:
|
else:
|
||||||
meta = await handler.meta()
|
if not redir:
|
||||||
image = meta.get("og:image")
|
meta = await handler.meta()
|
||||||
if isinstance(image, str):
|
image = meta.get("og:image")
|
||||||
if handler.provider == "youtube" and image.endswith("hqdefault.jpg"):
|
if isinstance(image, str):
|
||||||
image = image.removesuffix("hqdefault.jpg") + "maxresdefault.jpg"
|
if handler.provider == "youtube":
|
||||||
image = await handler.proxy.proxy_url(image, None)
|
full_image = None
|
||||||
if isinstance(image, str):
|
image_type = None
|
||||||
self.set_header("Custom-Poster", image)
|
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)
|
||||||
|
if isinstance(image, str):
|
||||||
|
self.set_header("Custom-Poster", image)
|
||||||
upstream = await stream_providers.get_any(handler.upstream, handler.proxy, logger)
|
upstream = await stream_providers.get_any(handler.upstream, handler.proxy, logger)
|
||||||
if upstream is None:
|
if upstream is None:
|
||||||
logger.info(f'invalid upstream ({handler.provider})')
|
logger.info(f'invalid upstream ({handler.provider})')
|
||||||
|
Loading…
Reference in New Issue
Block a user