Add more meta tags
This commit is contained in:
parent
add8f1bbde
commit
e9eb88c13f
36
app.py
36
app.py
@ -231,6 +231,8 @@ def proxy(video_id):
|
||||
|
||||
cdn_video_url = get_cdn_url(video_id)
|
||||
og_tags = soup.find_all("meta", property=lambda x: x) # type: ignore
|
||||
og_video_width = None
|
||||
og_video_height = None
|
||||
for tag in og_tags:
|
||||
# Fix thumbnail
|
||||
if tag.get("property") == "og:image" and thumbnail_url:
|
||||
@ -238,19 +240,31 @@ def proxy(video_id):
|
||||
# Fix video URL
|
||||
if tag.get("property") == "og:video:url" or tag.get("property") == "og:video:secure_url":
|
||||
tag["content"] = cdn_video_url
|
||||
# Set vars
|
||||
if tag.get("property") == "og:video:width":
|
||||
og_video_width = tag.get("content")
|
||||
if tag.get("property") == "og:video:height":
|
||||
og_video_height = tag.get("content")
|
||||
|
||||
og_tags_str = "\n".join(str(tag) for tag in og_tags)
|
||||
html_response = f"""
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
{og_tags_str}
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
og_tags_str += '\n<meta content="0" property="twitter:image"/>'
|
||||
og_tags_str += '\n<meta content="player" property="twitter:card"/>'
|
||||
og_tags_str += f'\n<meta content="{cdn_video_url}" property="twitter:player:stream"/>'
|
||||
if og_video_width:
|
||||
og_tags_str += f'\n<meta content="{og_video_width}" property="twitter:player:width"/>'
|
||||
if og_video_height:
|
||||
og_tags_str += f'\n<meta content="{og_video_height}" property="twitter:player:height"/>'
|
||||
html_response = f"""<!DOCTYPE html>
|
||||
<!--
|
||||
niconico proxy - brought to you by https://mmaker.moe
|
||||
|
||||
this service is intended to be used by social media open graph embed generators and discordbot.
|
||||
please do not abuse! the videos returned by the CDN are lower quality and intended to only be proxied by discord, not hotlinked.
|
||||
if you want to download videos, please consider using a tool like nndownload: https://github.com/AlexAplin/nndownload
|
||||
-->
|
||||
<html lang="en"><head><meta charset="UTF-8">
|
||||
{og_tags_str}
|
||||
</head><body></body></html>"""
|
||||
|
||||
if cache:
|
||||
logging.info(f"Caching response for video ID: {video_id}")
|
||||
|
Loading…
x
Reference in New Issue
Block a user