feat: add SoundCloud -> SoundCloak replacement support

This commit is contained in:
2025-11-18 15:51:32 -03:00
parent 3256ba8b03
commit 5e60c28ce5
2 changed files with 11 additions and 0 deletions

View File

@@ -17,6 +17,8 @@ let
imgurLinkRegex = re"""<a href="https://(i\.)?imgur.com([^"]+)">(i\.)?imgur\.com(\S+)</a>"""
fandomRegex = re"(?<=(?<!\S)https:\/\/|(?<=\s))([a-z0-9-]+)\.fandom\.com"
fandomLinkRegex = re"""<a href="https://([a-z0-9-]+)\.fandom\.com([^"]+)">([a-z0-9-]+)\.fandom\.com(\S+)</a>"""
soundcloudRegex = re"(?<=(?<!\S)https:\/\/|(?<=\s))(www\.)?soundcloud\.com"
soundcloudLinkRegex = re"""<a href="https://(www\.)?soundcloud\.com([^"]+)">(www\.)?soundcloud\.com(\S+)</a>"""
ytRegex = re(r"([A-z.]+\.)?youtu(be\.com|\.be)", {reStudy, reIgnoreCase})
@@ -87,6 +89,11 @@ proc replaceUrls*(body: string; prefs: Prefs; absolute=""): string =
result = result.replacef(fandomLinkRegex, a(
prefs.replaceFandom & "/$1$2", href = https & prefs.replaceFandom & "/$1$2"))
if prefs.replaceSoundCloud.len > 0 and "soundcloud.com" in result:
result = result.replace(soundcloudRegex, prefs.replaceSoundCloud)
result = result.replacef(soundcloudLinkRegex, a(
prefs.replaceSoundCloud & "$4", href = https & prefs.replaceSoundCloud & "$2"))
if prefs.replaceReddit.len > 0 and ("reddit.com" in result or "redd.it" in result):
result = result.replace(rdShortRegex, prefs.replaceReddit & "/comments/")
result = result.replace(rdRegex, prefs.replaceReddit)

View File

@@ -115,6 +115,10 @@ genPrefs:
"Fandom -> Phantom"
placeholder: "Phantom hostname"
replaceSoundCloud(input, ""):
"SoundCloud -> SoundCloak"
placeholder: "SoundCloak hostname"
iterator allPrefs*(): Pref =
for k, v in prefList:
for pref in v: