diff --git a/app.py b/app.py index 00cb7c6..445ae21 100644 --- a/app.py +++ b/app.py @@ -337,6 +337,7 @@ def proxy(video_id): logger.warning(f"{video_id}: No Open Graph tags found") og_title = None og_description = None + og_category = None for tag in og_tags: # Remove attribute(s) added by niconico if 'data-server' in tag.attrs: @@ -347,6 +348,14 @@ def proxy(video_id): # Set description if tag.get("property") == "og:description": og_description = tag["content"] + if og_description and og_title: + # The description is formatted like "Title [Category] Description" + # Extract category (just incase this is useful later), and keep only the description part. + match = re.search(rf"^{re.escape(og_title)}(\s+\[(.*?)\])?\s+(.*)", og_description) + if match: + og_category = match.group(2) if match.group(2) else None + og_description = match.group(3) + tag["content"] = og_description # Fix thumbnail if tag.get("property") == "og:image" and thumbnail_url: tag["content"] = thumbnail_url @@ -366,8 +375,6 @@ def proxy(video_id): if og_title: og_tags_str += f'\n' if og_description: - if og_title: - og_description = re.sub(rf"^{re.escape(og_title)}(\s+\[.*?\])?\s+", "", og_description) og_tags_str += f'\n' # og_tags_str += '\n' # og_tags_str += f'\n'