From 2d9b42237eff9e03cab376547b4bcff4e3b2dcb1 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sat, 13 Aug 2022 10:26:33 +0200 Subject: [PATCH] fix https://rdrama.org/post/18459/marseycapywalking-megathread-for-bugs-and-suggestions/2497656?context=8#context --- files/classes/comment.py | 5 ++--- files/helpers/actions.py | 8 ++++++++ files/helpers/regex.py | 2 ++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/files/classes/comment.py b/files/classes/comment.py index b761590b6..beb65faff 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -19,9 +19,8 @@ from math import floor def normalize_urls_runtime(body, v): - if v: - body = body.replace("https://old.reddit.com/r/", f'https://{v.reddit}/r/').replace("https://old.reddit.com/u/", f'https://{v.reddit}/u/') - + if v.reddit != 'old.reddit.com': + body = reddit_to_vreddit_regex.sub(rf'\1https://{v.reddit}/\2/', body) if v.nitter: body = twitter_to_nitter_regex.sub(r'https://nitter.42l.fr/\1', body) return body diff --git a/files/helpers/actions.py b/files/helpers/actions.py index 418a19a6c..25a06b50c 100644 --- a/files/helpers/actions.py +++ b/files/helpers/actions.py @@ -90,6 +90,10 @@ def execute_snappy(post, v): body += f"Snapshots:\n\n{rev}* [archive.org](https://web.archive.org/{newposturl})\n* [archive.ph](https://archive.ph/?url={quote(newposturl)}&run=1) (click to archive)\n* [ghostarchive.org](https://ghostarchive.org/search?term={quote(newposturl)}) (click to archive)\n\n" gevent.spawn(archiveorg, newposturl) + if newposturl.startswith('https://twitter.com/'): + newposturl = newposturl.replace('https://twitter.com/', 'https://nitter.42l.fr/') + gevent.spawn(archiveorg, newposturl) + captured = [] body_for_snappy = post.body_html.replace(' data-src="', ' src="') @@ -124,6 +128,10 @@ def execute_snappy(post, v): body += addition gevent.spawn(archiveorg, href) + if href.startswith('https://twitter.com/'): + href = href.replace('https://twitter.com/', 'https://nitter.42l.fr/') + gevent.spawn(archiveorg, href) + body = body.strip() body_html = sanitize(body) diff --git a/files/helpers/regex.py b/files/helpers/regex.py index 2dedea036..70ebbd0c0 100644 --- a/files/helpers/regex.py +++ b/files/helpers/regex.py @@ -92,6 +92,8 @@ ascii_only_regex = re.compile("[ -~]+", flags=re.A) twitter_to_nitter_regex = re.compile("https:\/\/twitter.com\/(\w{2,15}(\/status\/\d+[^/]*)?)", flags=re.A) +reddit_to_vreddit_regex = re.compile('([>"])https:\/\/old.reddit.com\/(r|u)\/', flags=re.A) + reddit_domain_regex = re.compile("(^|\s|\()https?:\/\/(reddit\.com|new\.reddit.com|www\.reddit.com|i\.reddit\.com|libredd\.it|teddit\.net)\/(r|u)\/", flags=re.A) color_regex = re.compile("[a-z0-9]{6}", flags=re.A)