From 255a12fcc62b2ae0983ae2cb773c9dd97bb9df0d Mon Sep 17 00:00:00 2001 From: MMaker Date: Mon, 3 Mar 2025 12:49:17 -0500 Subject: [PATCH] Attempt to fix Twitter card display v2 --- app.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index 80ce5e8..1fbf4b2 100644 --- a/app.py +++ b/app.py @@ -331,10 +331,18 @@ def proxy(video_id): cdn_video_url = get_cdn_url(video_id) og_tags = soup.find_all("meta", attrs={"property": True}) + og_title = None + og_description = None for tag in og_tags: # Remove attribute(s) added by niconico if 'data-server' in tag.attrs: del tag.attrs['data-server'] + # Set title + if tag.get("property") == "og:title": + og_title = tag["content"] + # Set description + if tag.get("property") == "og:description": + og_description = tag["content"] # Fix thumbnail if tag.get("property") == "og:image" and thumbnail_url: tag["content"] = thumbnail_url @@ -343,8 +351,15 @@ def proxy(video_id): tag["content"] = cdn_video_url og_tags_str = "\n".join(str(tag) for tag in og_tags if tag.get("property") not in ["og:site_name"]) - # og_tags_str += '\n' - # og_tags_str += '\n' + if 'twitterbot' in request_user_agent: + og_tags_str += f'\n' + og_tags_str += '\n' + og_tags_str += '\n' + og_tags_str += f'\n' + if og_title: + og_tags_str += f'\n' + if og_description: + og_tags_str += f'\n' # og_tags_str += '\n' # og_tags_str += f'\n' # if video_width: