From 831344b72395b74df2ed782d932ecdbb6ae26e1a Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sat, 11 Jun 2022 14:21:59 +0200 Subject: [PATCH] small image embed improvements --- files/helpers/const.py | 11 +++++++---- files/helpers/sanitize.py | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/files/helpers/const.py b/files/helpers/const.py index 3ac0edb0d..7e51399b4 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -1002,7 +1002,6 @@ approved_embed_hosts = { 'tumblr.com', 'yarn.co', 'gifer.com', - 'prnt.sc', 'staticflickr.com', 'kiwifarms.net', 'amazonaws.com', @@ -1016,7 +1015,11 @@ approved_embed_hosts = { 'bing.com', 'typekit.net', 'postimg.cc', - 'archive.org' + 'archive.org', + 'substackcdn.com', + '9gag.com', + 'ifunny.co', + 'wixmp.com', } @@ -1032,13 +1035,13 @@ video_sub_regex = re.compile(f'(

[^<]*)(https:\/\/([a-z0-9-]+\.)*({hosts})\/[\ audio_sub_regex = re.compile(f'(

[^<]*)(https:\/\/([a-z0-9-]+\.)*({hosts})\/[\w:~,()\-.#&\/=?@%;+]*?\.(mp3|wav|ogg|aac|m4a|flac))', flags=re.A) imgur_regex = re.compile('(https:\/\/i\.imgur\.com\/[a-z0-9]+)\.(jpg|png|jpeg|webp)(?!<\/(code|pre|a)>)', flags=re.I|re.A) -giphy_tenor_regex = re.compile('(https:\/\/(media\.giphy\.com|c\.tenor\.com)\/[\/\-a-z0-9]+)\.gif(?!<\/(code|pre|a)>)', flags=re.I|re.A) +giphy_regex = re.compile('(https:\/\/media\.giphy\.com\/media\/[a-z0-9]+\/giphy)\.gif', flags=re.I|re.A) youtube_regex = re.compile('(

[^<]*)(https:\/\/youtube\.com\/watch\?v\=([a-z0-9-_]{5,20})[\w\-.#&/=\?@%+]*)', flags=re.I|re.A) yt_id_regex = re.compile('[a-z0-9-_]{5,20}', flags=re.I|re.A) -image_regex = re.compile("(^|\s)(https:\/\/[\w\-.#&/=\?@%;+]{5,250}(\.png|\.jpg|\.jpeg|\.gif|\.webp|maxwidth=9999|fidelity=high))($|\s)", flags=re.I|re.A) +image_regex = re.compile("(^|\s)(https:\/\/[\w\-.#&/=\?@%;+,:]{5,250}(\.png|\.jpg|\.jpeg|\.gif|\.webp)(\?[\w\-.#&/=\?@%;+,:]*)?)($|\s)", flags=re.I|re.A) link_fix_regex = re.compile("(?!.*(http|\/))(.*\[[^\]]+\]\()([^)]+\))", flags=re.A) diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 44e123f02..606b55250 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -168,7 +168,7 @@ def sanitize(sanitized, alert=False, comment=False, edit=False): if '```' not in sanitized and '

' not in sanitized:
 		sanitized = linefeeds_regex.sub(r'\1\n\n\2', sanitized)
 
-	sanitized = image_regex.sub(r'\1![](\2)\4', sanitized)
+	sanitized = image_regex.sub(r'\1![](\2)\5', sanitized)
 
 	sanitized = image_check_regex.sub(r'\1', sanitized)
 
@@ -395,6 +395,6 @@ def normalize_url(url):
 			 .replace("https://streamable.com/e/e/", "https://streamable.com/e/")
 
 	url = imgur_regex.sub(r'\1_d.webp?maxwidth=9999&fidelity=high', url)
-	url = giphy_tenor_regex.sub(r'\1.webp', url)
+	url = giphy_regex.sub(r'\1.webp', url)
 
 	return url