make snappy archive youtube videos too

remotes/1693045480750635534/spooky-22
Aevann1 2022-07-11 19:45:07 +02:00
parent 34089912c2
commit bab105223b
2 changed files with 13 additions and 5 deletions

View File

@ -91,14 +91,21 @@ def execute_snappy(post, v):
captured = []
body_for_snappy = post.body_html.replace(' data-src="', ' src="')
for i in list(snappy_url_regex.finditer(body_for_snappy)):
if i.group(1) in captured: continue
captured.append(i.group(1))
href = i.group(1)
if not href: continue
if href in [x[0] for x in captured]: continue
title = i.group(2)
captured.append((href, title))
for i in list(snappy_youtube_regex.finditer(body_for_snappy)):
href = f'https://youtube.com/watch?v={i.group(1)}'
if href in [x[0] for x in captured]: continue
captured.append((href, href))
for href, title in captured:
if "Snapshots:\n\n" not in body: body += "Snapshots:\n\n"
if f'**[{title}]({href})**:\n\n' not in body:

View File

@ -50,6 +50,7 @@ emoji_regex2 = re.compile(f'(?<!"):([!#@{valid_username_chars}]{{1,36}}?):', fla
emoji_regex3 = re.compile(f'(?<!"):([!@{valid_username_chars}]{{1,35}}?):', flags=re.A)
snappy_url_regex = re.compile('<a href="(https?:\/\/.+?)".*?>(.+?)<\/a>', flags=re.A)
snappy_youtube_regex = re.compile('<lite-youtube videoid="(.+?)" params="autoplay=1', flags=re.A)
email_regex = re.compile('[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}', flags=re.A|re.I)