Convert youtu.be links to youtube.com so they embed in post

This commit is contained in:
freamon 2024-09-06 01:06:24 +00:00
parent 6741b1a35a
commit 9e8066bc4e
3 changed files with 6 additions and 5 deletions

View file

@ -1059,7 +1059,7 @@ class Post(db.Model):
if self.url:
vpos = self.url.find('v=')
if vpos != -1:
return self.url[vpos + 2:vpos + 13]
return self.url[vpos + 2:vpos + 13] + '?rel=0' + self.url[vpos + 13:]
def peertube_embed(self):
if self.url:

View file

@ -99,7 +99,7 @@
{% endif -%}
{% if 'youtube.com' in post.url -%}
<p><a href="https://piped.video/watch?v={{ post.youtube_embed() }}">{{ _('Watch on piped.video') }} <span class="fe fe-external"></span></a></p>
<div style="padding-bottom: 56.25%; position: relative;"><iframe style="position: absolute; top: 0px; left: 0px; width: 100%; height: 100%;" src="https://www.youtube.com/embed/{{ post.youtube_embed() }}?rel=0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture; fullscreen" width="100%" height="100%" frameborder="0"></iframe></div>
<div style="padding-bottom: 56.25%; position: relative;"><iframe style="position: absolute; top: 0px; left: 0px; width: 100%; height: 100%;" src="https://www.youtube.com/embed/{{ post.youtube_embed() }}" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture; fullscreen" width="100%" height="100%" frameborder="0"></iframe></div>
{% endif -%}
{% elif post.type == POST_TYPE_VIDEO -%}
<p><a href="{{ post.url }}" rel="nofollow ugc" target="_blank" class="post_link" aria-label="Go to post url">{{ post.url|shorten_url }}
@ -120,7 +120,7 @@
{% endif -%}
{% if 'youtube.com' in post.url -%}
<p><a href="https://piped.video/watch?v={{ post.youtube_embed() }}">{{ _('Watch on piped.video') }} <span class="fe fe-external"></span></a></p>
<div style="padding-bottom: 56.25%; position: relative;"><iframe style="position: absolute; top: 0px; left: 0px; width: 100%; height: 100%;" src="https://www.youtube.com/embed/{{ post.youtube_embed() }}?rel=0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture; fullscreen" width="100%" height="100%" frameborder="0"></iframe></div>
<div style="padding-bottom: 56.25%; position: relative;"><iframe style="position: absolute; top: 0px; left: 0px; width: 100%; height: 100%;" src="https://www.youtube.com/embed/{{ post.youtube_embed() }}" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture; fullscreen" width="100%" height="100%" frameborder="0"></iframe></div>
{% endif -%}
{% if 'videos/watch' in post.url -%}
<div style="padding-bottom: 56.25%; position: relative;"><iframe style="position: absolute; top: 0px; left: 0px; width: 100%; height: 100%;" src="{{ post.peertube_embed() }}" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture; fullscreen" width="100%" height="100%" frameborder="0"></iframe></div>

View file

@ -1060,9 +1060,10 @@ def remove_tracking_from_link(url):
else:
new_query_string = ''
cleaned_url = f"https://youtu.be/{video_id}"
cleaned_url = f"https://youtube.com/watch?v={video_id}"
if new_query_string:
cleaned_url += f"?{new_query_string}"
new_query_string = new_query_string.replace('t=', 'start=')
cleaned_url += f"&{new_query_string}"
return cleaned_url
else: