refactor nitter

master
Aevann1 2022-08-16 18:53:24 +02:00
parent 6b4e582f7e
commit 7edd569090
2 changed files with 5 additions and 4 deletions

View File

@ -21,8 +21,11 @@ def normalize_urls_runtime(body, v):
if v and v.reddit != 'old.reddit.com': if v and v.reddit != 'old.reddit.com':
body = reddit_to_vreddit_regex.sub(rf'\1https://{v.reddit}/\2/', body) 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) if v.nitter:
if v.imginn: body = body.replace('https://instagram.com/', 'https://imginn.com/') body = body.replace('https://twitter.com/', 'https://nitter.42l.fr/')
body = body.replace('https://nitter.42l.fr/i/', 'https://twitter.com/i/')
if v.imginn:
body = body.replace('https://instagram.com/', 'https://imginn.com/')
return body return body

View File

@ -90,8 +90,6 @@ greentext_regex = re.compile("(\n|^)>([^ >][^\n]*)", flags=re.A)
ascii_only_regex = re.compile("[ -~]+", flags=re.A) 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_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) 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)