make the "https://" optional to embed a youtube video (I rly hope i dont regret this)

pull/143/head
Aevann 2023-04-25 09:35:01 +02:00
parent 146ee51b05
commit 5ad46f3e53
2 changed files with 8 additions and 7 deletions

View File

@ -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('(<p>[^<]*)(https:\/\/youtube\.com\/watch\?[\w\-.#&/=?@%+]{7,})', flags=re.I|re.A)
youtube_regex = re.compile('(<p>[^<]*)((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)

View File

@ -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") \