From 3c45630062dca8b749097929b034cfc8c1174fd7 Mon Sep 17 00:00:00 2001 From: Zed Date: Mon, 27 Dec 2021 02:13:05 +0100 Subject: [PATCH] Add Reddit link replacement support Closes #306 Closes #353 --- nitter.conf | 1 + src/formatters.nim | 16 +++++++++++++++- src/prefs_impl.nim | 4 ++++ tests/test_tweet.py | 2 +- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/nitter.conf b/nitter.conf index d4f7361..9c10317 100644 --- a/nitter.conf +++ b/nitter.conf @@ -34,6 +34,7 @@ tokenCount = 10 theme = "Nitter" replaceTwitter = "nitter.net" replaceYouTube = "piped.kavin.rocks" +replaceReddit = "teddit.net" replaceInstagram = "" proxyVideos = true hlsPlayback = false diff --git a/src/formatters.nim b/src/formatters.nim index f56658c..164e0a7 100644 --- a/src/formatters.nim +++ b/src/formatters.nim @@ -4,8 +4,16 @@ import types, utils, query const ytRegex = re"([A-z.]+\.)?youtu(be\.com|\.be)" - twRegex = re"(? ])(? ])(? 0 and (rdRegex in result or "redd.it" in result): + result = result.replace(rdShortRegex, prefs.replaceReddit & "/comments/") + result = result.replace(rdRegex, prefs.replaceReddit) + if prefs.replaceReddit in result and "/gallery/" in result: + result = result.replace("/gallery/", "/comments/") + if prefs.replaceInstagram.len > 0 and igRegex in result: result = result.replace(igRegex, prefs.replaceInstagram) diff --git a/src/prefs_impl.nim b/src/prefs_impl.nim index 520f59d..80d90f7 100644 --- a/src/prefs_impl.nim +++ b/src/prefs_impl.nim @@ -58,6 +58,10 @@ genPrefs: "Replace YouTube links with Piped/Invidious (blank to disable)" placeholder: "Piped hostname" + replaceReddit(input, "teddit.net"): + "Replace Reddit links with Teddit/Libreddit (blank to disable)" + placeholder: "Teddit hostname" + replaceInstagram(input, ""): "Replace Instagram links with Bibliogram (blank to disable)" placeholder: "Bibliogram hostname" diff --git a/tests/test_tweet.py b/tests/test_tweet.py index a7a059c..e8ba0f7 100644 --- a/tests/test_tweet.py +++ b/tests/test_tweet.py @@ -42,7 +42,7 @@ link = [ ['nim_lang/status/1110499584852353024', [ 'nim-lang.org/araq/ownedrefs.…', 'news.ycombinator.com/item?id…', - 'old.reddit.com/r/programming…' + 'teddit.net/r/programming…' ]], ['nim_lang/status/1125887775151140864', [ 'en.wikipedia.org/wiki/Nim_(p…'