From 6e41e842fd0f1ebacf6001ef8125465708f080a2 Mon Sep 17 00:00:00 2001 From: MMaker Date: Mon, 3 Mar 2025 12:44:40 -0500 Subject: [PATCH] Attempt to fix Twitter card display --- app.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index 80ce5e8..adb2273 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,14 @@ 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' + 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: