From bab105223b0d5ec766179b626e6d999420c4c153 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Mon, 11 Jul 2022 19:45:07 +0200 Subject: [PATCH] make snappy archive youtube videos too --- files/helpers/actions.py | 17 ++++++++++++----- files/helpers/regex.py | 1 + 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/files/helpers/actions.py b/files/helpers/actions.py index f22c513ce..a1ea6ec93 100644 --- a/files/helpers/actions.py +++ b/files/helpers/actions.py @@ -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: diff --git a/files/helpers/regex.py b/files/helpers/regex.py index 3504a1abc..5dc8dff84 100644 --- a/files/helpers/regex.py +++ b/files/helpers/regex.py @@ -50,6 +50,7 @@ emoji_regex2 = re.compile(f'(?(.+?)<\/a>', flags=re.A) +snappy_youtube_regex = re.compile('