mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-02-02 16:21:32 -08:00
Clean tracking info from youtube links
This commit is contained in:
parent
3e5d040beb
commit
9fa260632a
3 changed files with 15 additions and 3 deletions
|
@ -24,7 +24,7 @@ import pytesseract
|
|||
|
||||
from app.utils import get_request, allowlist_html, html_to_markdown, get_setting, ap_datetime, markdown_to_html, \
|
||||
is_image_url, domain_from_url, gibberish, ensure_directory_exists, markdown_to_text, head_request, post_ranking, \
|
||||
shorten_string, reply_already_exists, reply_is_just_link_to_gif_reaction, confidence
|
||||
shorten_string, reply_already_exists, reply_is_just_link_to_gif_reaction, confidence, clean_link
|
||||
|
||||
|
||||
def public_key():
|
||||
|
@ -1227,6 +1227,7 @@ def create_post(activity_log: ActivityPubLog, community: Community, request_json
|
|||
post.image = image
|
||||
else:
|
||||
post.type = POST_TYPE_LINK
|
||||
post.url = clean_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
|
||||
|
|
|
@ -15,7 +15,7 @@ from app.constants import POST_TYPE_ARTICLE, POST_TYPE_LINK, POST_TYPE_IMAGE
|
|||
from app.models import Community, File, BannedInstances, PostReply, PostVote, Post, utcnow, CommunityMember, Site, \
|
||||
Instance, Notification, User
|
||||
from app.utils import get_request, gibberish, markdown_to_html, domain_from_url, allowlist_html, \
|
||||
html_to_markdown, is_image_url, ensure_directory_exists, inbox_domain, post_ranking, shorten_string, parse_page
|
||||
html_to_markdown, is_image_url, ensure_directory_exists, inbox_domain, post_ranking, shorten_string, parse_page, clean_link
|
||||
from sqlalchemy import func
|
||||
import os
|
||||
|
||||
|
@ -177,7 +177,7 @@ def save_post(form, post: Post):
|
|||
post.body = form.link_body.data
|
||||
post.body_html = markdown_to_html(post.body)
|
||||
url_changed = post.id is None or form.link_url.data != post.url
|
||||
post.url = form.link_url.data
|
||||
post.url = clean_link(form.link_url.data)
|
||||
post.type = POST_TYPE_LINK
|
||||
domain = domain_from_url(form.link_url.data)
|
||||
domain.post_count += 1
|
||||
|
|
11
app/utils.py
11
app/utils.py
|
@ -745,3 +745,14 @@ def sha256_digest(input_string):
|
|||
sha256_hash = hashlib.sha256()
|
||||
sha256_hash.update(input_string.encode('utf-8'))
|
||||
return sha256_hash.hexdigest()
|
||||
|
||||
|
||||
def clean_link(url):
|
||||
# strip ?si=abcDEFgh from youtu.be links
|
||||
clean = re.search(r"(https://youtu.be/\w+)", url)
|
||||
|
||||
if clean is not None:
|
||||
return clean.group(1)
|
||||
else:
|
||||
return url
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue