mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
0c7cd6d34c
5 changed files with 18 additions and 9 deletions
|
@ -1940,7 +1940,6 @@ def create_post(activity_log: ActivityPubLog, community: Community, request_json
|
||||||
post.image = image
|
post.image = image
|
||||||
else:
|
else:
|
||||||
post.type = POST_TYPE_LINK
|
post.type = POST_TYPE_LINK
|
||||||
post.url = remove_tracking_from_link(post.url)
|
|
||||||
domain = domain_from_url(post.url)
|
domain = domain_from_url(post.url)
|
||||||
# notify about links to banned websites.
|
# notify about links to banned websites.
|
||||||
already_notified = set() # often admins and mods are the same people - avoid notifying them twice
|
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
|
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
|
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!
|
# 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', '') != ''):
|
if opengraph and (opengraph.get('og:image', '') != '' or opengraph.get('og:image:url', '') != ''):
|
||||||
filename = 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('/'):
|
if not filename.startswith('/'):
|
||||||
|
@ -2003,6 +2005,8 @@ def create_post(activity_log: ActivityPubLog, community: Community, request_json
|
||||||
post.image = file
|
post.image = file
|
||||||
db.session.add(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)
|
db.session.add(post)
|
||||||
post.ranking = post_ranking(post.score, post.posted_at)
|
post.ranking = post_ranking(post.score, post.posted_at)
|
||||||
community.post_count += 1
|
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']
|
alt_text = request_json['object']['attachment'][0]['name']
|
||||||
if post.url == '':
|
if post.url == '':
|
||||||
post.type = POST_TYPE_ARTICLE
|
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.url and post.url != old_url) or (post.url == '' and old_url != ''):
|
||||||
if post.image_id:
|
if post.image_id:
|
||||||
old_image = File.query.get(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
|
post.image = image
|
||||||
else:
|
else:
|
||||||
post.type = POST_TYPE_LINK
|
post.type = POST_TYPE_LINK
|
||||||
post.url = remove_tracking_from_link(post.url)
|
|
||||||
domain = domain_from_url(post.url)
|
domain = domain_from_url(post.url)
|
||||||
# notify about links to banned websites.
|
# notify about links to banned websites.
|
||||||
already_notified = set() # often admins and mods are the same people - avoid notifying them twice
|
already_notified = set() # often admins and mods are the same people - avoid notifying them twice
|
||||||
|
|
|
@ -287,7 +287,10 @@ def save_post(form, post: Post, type: int):
|
||||||
else:
|
else:
|
||||||
# check opengraph tags on the page and make a thumbnail if an image is available in the og:image meta tag
|
# 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:
|
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', '') != ''):
|
if opengraph and (opengraph.get('og:image', '') != '' or opengraph.get('og:image:url', '') != ''):
|
||||||
filename = 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('/'):
|
if not filename.startswith('/'):
|
||||||
|
|
|
@ -1059,7 +1059,7 @@ class Post(db.Model):
|
||||||
if self.url:
|
if self.url:
|
||||||
vpos = self.url.find('v=')
|
vpos = self.url.find('v=')
|
||||||
if vpos != -1:
|
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):
|
def peertube_embed(self):
|
||||||
if self.url:
|
if self.url:
|
||||||
|
|
|
@ -99,7 +99,7 @@
|
||||||
{% endif -%}
|
{% endif -%}
|
||||||
{% if 'youtube.com' in post.url -%}
|
{% 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>
|
<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 -%}
|
{% endif -%}
|
||||||
{% elif post.type == POST_TYPE_VIDEO -%}
|
{% 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 }}
|
<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 -%}
|
{% endif -%}
|
||||||
{% if 'youtube.com' in post.url -%}
|
{% 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>
|
<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 -%}
|
{% endif -%}
|
||||||
{% if 'videos/watch' in post.url -%}
|
{% 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>
|
<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>
|
||||||
|
|
|
@ -1060,9 +1060,10 @@ def remove_tracking_from_link(url):
|
||||||
else:
|
else:
|
||||||
new_query_string = ''
|
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:
|
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
|
return cleaned_url
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Reference in a new issue