Merge remote-tracking branch 'origin/main'

This commit is contained in:
rimu 2024-09-06 15:43:33 +12:00
commit 0c7cd6d34c
5 changed files with 18 additions and 9 deletions

View file

@ -1940,7 +1940,6 @@ def create_post(activity_log: ActivityPubLog, community: Community, request_json
post.image = image
else:
post.type = POST_TYPE_LINK
post.url = remove_tracking_from_link(post.url)
domain = domain_from_url(post.url)
# notify about links to banned websites.
already_notified = set() # often admins and mods are the same people - avoid notifying them twice
@ -1995,7 +1994,10 @@ def create_post(activity_log: ActivityPubLog, community: Community, request_json
post.image = image
if post.image is None and post.type == POST_TYPE_LINK: # This is a link post but the source instance has not provided a thumbnail image
# Let's see if we can do better than the source instance did!
opengraph = opengraph_parse(post.url)
tn_url = post.url
if tn_url[:32] == 'https://www.youtube.com/watch?v=':
tn_url = 'https://youtu.be/' + tn_url[32:43] # better chance of thumbnail from youtu.be than youtube.com
opengraph = opengraph_parse(tn_url)
if opengraph and (opengraph.get('og:image', '') != '' or opengraph.get('og:image:url', '') != ''):
filename = opengraph.get('og:image') or opengraph.get('og:image:url')
if not filename.startswith('/'):
@ -2003,6 +2005,8 @@ def create_post(activity_log: ActivityPubLog, community: Community, request_json
post.image = file
db.session.add(file)
if post.url:
post.url = remove_tracking_from_link(post.url) # moved here as changes youtu.be to youtube.com
db.session.add(post)
post.ranking = post_ranking(post.score, post.posted_at)
community.post_count += 1
@ -2184,6 +2188,8 @@ def update_post_from_activity(post: Post, request_json: dict):
alt_text = request_json['object']['attachment'][0]['name']
if post.url == '':
post.type = POST_TYPE_ARTICLE
else:
post.url = remove_tracking_from_link(post.url)
if (post.url and post.url != old_url) or (post.url == '' and old_url != ''):
if post.image_id:
old_image = File.query.get(post.image_id)
@ -2209,7 +2215,6 @@ def update_post_from_activity(post: Post, request_json: dict):
post.image = image
else:
post.type = POST_TYPE_LINK
post.url = remove_tracking_from_link(post.url)
domain = domain_from_url(post.url)
# notify about links to banned websites.
already_notified = set() # often admins and mods are the same people - avoid notifying them twice

View file

@ -287,7 +287,10 @@ def save_post(form, post: Post, type: int):
else:
# check opengraph tags on the page and make a thumbnail if an image is available in the og:image meta tag
if not post.type == POST_TYPE_VIDEO:
opengraph = opengraph_parse(form.link_url.data)
tn_url = form.link_url.data
if tn_url[:32] == 'https://www.youtube.com/watch?v=':
tn_url = 'https://youtu.be/' + tn_url[32:43] # better chance of thumbnail from youtu.be than youtube.com
opengraph = opengraph_parse(tn_url)
if opengraph and (opengraph.get('og:image', '') != '' or opengraph.get('og:image:url', '') != ''):
filename = opengraph.get('og:image') or opengraph.get('og:image:url')
if not filename.startswith('/'):

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: