diff --git a/files/helpers/regex.py b/files/helpers/regex.py index 24682b32bf..b8d359ea36 100644 --- a/files/helpers/regex.py +++ b/files/helpers/regex.py @@ -87,7 +87,7 @@ imgur_regex = re.compile(f'(https:\/\/i\.imgur\.com\/[a-z0-9]+)\.({image_regex_e 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\?[\w\-.#&/=?@%+]{7,})', flags=re.I|re.A) +youtube_regex = re.compile('(
[^<]*)((https:\/\/)?youtube\.com\/watch\?[\w\-.#&/=?@%+]{7,})', flags=re.I|re.A) yt_id_regex = re.compile('[\w\-]{5,20}', flags=re.A) link_fix_regex = re.compile("(\[.*?\]\()(?!http|\/)(.*?\))(?!([^<]*<\/(code|pre|a)>|[^`]*`))", flags=re.A) diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index fdb3e98b96..dcb3b5f011 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -576,12 +576,13 @@ def filter_emojis_only(title, golden=True, count_emojis=False, graceful=False, s def normalize_url(url): url = reddit_domain_regex.sub(r'\1https://old.reddit.com/\3/', url) - url = url.replace("https://youtu.be/", "https://youtube.com/watch?v=") \ - .replace("https://music.youtube.com/watch?v=", "https://youtube.com/watch?v=") \ - .replace("https://www.youtube.com", "https://youtube.com") \ - .replace("https://m.youtube.com", "https://youtube.com") \ - .replace("https://youtube.com/shorts/", "https://youtube.com/watch?v=") \ - .replace("https://youtube.com/v/", "https://youtube.com/watch?v=") \ + url = url.replace("youtu.be/", "youtube.com/watch?v=") \ + .replace("music.youtube.com/watch?v=", "youtube.com/watch?v=") \ + .replace("www.youtube.com", "youtube.com") \ + .replace("m.youtube.com", "youtube.com") \ + .replace("youtube.com/shorts/", "youtube.com/watch?v=") \ + .replace("youtube.com/v/", "youtube.com/watch?v=") \ + \ .replace("https://mobile.twitter.com", "https://twitter.com") \ .replace("https://m.facebook.com", "https://facebook.com") \ .replace("https://m.wikipedia.org", "https://wikipedia.org") \