diff --git a/app/models.py b/app/models.py index 86befeec..032701e9 100644 --- a/app/models.py +++ b/app/models.py @@ -1154,6 +1154,19 @@ class Post(db.Model): return '' + def youtube_video_id(self) -> str: + if self.url: + parsed_url = urlparse(self.url) + query_params = parse_qs(parsed_url.query) + + if 'v' in query_params: + return query_params['v'][0] + if '/shorts/' in parsed_url.path: + video_id = parsed_url.path.split('/shorts/')[1].split('/')[0] + return f'{video_id}' + + return '' + def peertube_embed(self): if self.url: return self.url.replace('watch', 'embed') diff --git a/app/templates/post/post_teaser/_video.html b/app/templates/post/post_teaser/_video.html index a08f4326..f93b3d84 100644 --- a/app/templates/post/post_teaser/_video.html +++ b/app/templates/post/post_teaser/_video.html @@ -39,7 +39,7 @@ {% if 'youtube.com' in post.url -%}
- Video Thumbnail + Video Thumbnail
{% endif -%}