2023-01-16 16:36:14 +00:00
|
|
|
import random
|
|
|
|
import re
|
2024-06-27 15:35:35 +00:00
|
|
|
from typing import Callable
|
2024-02-05 11:09:23 +00:00
|
|
|
from urllib import parse
|
|
|
|
|
2023-01-16 16:36:14 +00:00
|
|
|
from qutebrowser.api import interceptor
|
2023-08-29 20:45:09 +00:00
|
|
|
from qutebrowser.extensions.interceptors import QUrl, RedirectException
|
2023-05-23 13:42:03 +00:00
|
|
|
from qutebrowser.utils import message
|
|
|
|
|
2023-08-29 20:45:09 +00:00
|
|
|
|
|
|
|
def fixScribePath(url: QUrl):
|
|
|
|
"""Fix external medium blog to scribe translation.
|
2023-05-23 13:42:03 +00:00
|
|
|
Some paths from medium will go through a 'global identity'
|
|
|
|
path which messes up the actual url path we want to go
|
|
|
|
to and puts it in queries. This puts it back on the path.
|
|
|
|
"""
|
2023-08-29 20:45:09 +00:00
|
|
|
# double unquoting necessary!
|
|
|
|
# I suppose we double-wrap it earlier somewhere?
|
|
|
|
# unquoted = parse.unquote(
|
|
|
|
# url.path(options=QUrl.ComponentFormattingOption.FullyEncoded)
|
|
|
|
# )
|
2023-10-03 11:43:00 +00:00
|
|
|
path = parse.unquote(f"{url.path()}{url.query()}", encoding="ascii")
|
2023-08-29 20:45:09 +00:00
|
|
|
url.setQuery(None)
|
|
|
|
new_path = re.sub(r"m/global-identity-2redirectUrl=", "", path)
|
|
|
|
url.setPath(
|
|
|
|
parse.quote(new_path),
|
|
|
|
mode=QUrl.ParsingMode.StrictMode,
|
|
|
|
)
|
|
|
|
return url
|
|
|
|
|
2023-01-16 16:36:14 +00:00
|
|
|
|
2024-06-27 15:35:35 +00:00
|
|
|
type Service = dict[str, list[str]]
|
|
|
|
type Redirects = dict[str, Service]
|
|
|
|
|
|
|
|
|
|
|
|
redirects: Redirects = {
|
2023-01-16 16:36:14 +00:00
|
|
|
"youtube": {
|
|
|
|
"source": ["youtube.com"],
|
2024-02-05 11:09:23 +00:00
|
|
|
"farside": ["invidious"],
|
|
|
|
},
|
|
|
|
"stackoverflow": {
|
2024-02-24 08:42:30 +00:00
|
|
|
"source": ["stackoverflow.com", "askubuntu.com"],
|
2024-02-05 11:09:23 +00:00
|
|
|
"farside": ["anonymousoverflow"],
|
2023-01-16 16:36:14 +00:00
|
|
|
},
|
|
|
|
"lbry": {
|
|
|
|
"source": ["odysee.com"],
|
2024-02-05 11:09:23 +00:00
|
|
|
"farside": ["librarian"],
|
2023-01-16 16:36:14 +00:00
|
|
|
},
|
|
|
|
"reddit": {
|
|
|
|
"source": ["reddit.com"],
|
2024-02-05 11:09:23 +00:00
|
|
|
"farside": ["redlib"],
|
|
|
|
},
|
|
|
|
"instagram": {
|
|
|
|
"source": ["instagram.com"],
|
|
|
|
"farside": ["proxigram"],
|
2023-01-16 16:36:14 +00:00
|
|
|
},
|
|
|
|
"twitter": {
|
|
|
|
"source": ["twitter.com"],
|
2024-02-05 11:09:23 +00:00
|
|
|
"farside": ["nitter"],
|
2023-01-16 16:36:14 +00:00
|
|
|
},
|
|
|
|
"imdb": {
|
|
|
|
"source": ["imdb.com"],
|
2024-02-05 11:09:23 +00:00
|
|
|
"farside": ["libremdb"],
|
2023-01-16 16:36:14 +00:00
|
|
|
},
|
|
|
|
"translate": {
|
|
|
|
"source": ["translate.google.com"],
|
2024-02-05 11:09:23 +00:00
|
|
|
"farside": ["lingva"],
|
2023-01-16 16:36:14 +00:00
|
|
|
},
|
|
|
|
"tiktok": {
|
|
|
|
"source": ["tiktok.com"],
|
2024-02-05 11:09:23 +00:00
|
|
|
"farside": ["proxitok"],
|
2023-01-16 16:36:14 +00:00
|
|
|
},
|
|
|
|
"imgur": {
|
|
|
|
"source": ["imgur.com"],
|
2024-02-05 11:09:23 +00:00
|
|
|
"farside": ["rimgo"],
|
2023-01-16 16:36:14 +00:00
|
|
|
},
|
|
|
|
"medium": {
|
|
|
|
"source": ["medium.com"],
|
2024-02-05 11:09:23 +00:00
|
|
|
"farside": ["scribe"],
|
|
|
|
# "postprocess": fixScribePath
|
|
|
|
},
|
|
|
|
"fandom": {
|
|
|
|
"source": ["fandom.com"],
|
|
|
|
"farside": ["breezewiki"],
|
|
|
|
},
|
|
|
|
"quora": {
|
|
|
|
"source": ["quora.com"],
|
|
|
|
"farside": ["quetre"],
|
|
|
|
# "postprocess": lambda url: message.info(f"CALLING QUORA WITH {url}")
|
2023-01-16 16:36:14 +00:00
|
|
|
},
|
|
|
|
"google": {
|
|
|
|
"source": ["google.com"],
|
|
|
|
"target": [
|
2024-02-05 11:09:23 +00:00
|
|
|
"search.albony.xyz",
|
|
|
|
"search.garudalinux.org",
|
|
|
|
"search.dr460nf1r3.org",
|
|
|
|
"s.tokhmi.xyz",
|
|
|
|
"search.sethforprivacy.com",
|
2023-01-16 16:36:14 +00:00
|
|
|
"whoogle.dcs0.hu",
|
2024-02-05 11:09:23 +00:00
|
|
|
"gowogle.voring.me",
|
|
|
|
"whoogle.privacydev.net",
|
|
|
|
"wg.vern.cc",
|
|
|
|
"whoogle.hxvy0.gq",
|
|
|
|
"whoogle.hostux.net",
|
|
|
|
"whoogle.lunar.icu",
|
|
|
|
"wgl.frail.duckdns.org",
|
|
|
|
"whoogle.no-logs.com",
|
|
|
|
"whoogle.ftw.lol",
|
|
|
|
"whoogle-search--replitcomreside.repl.co",
|
|
|
|
"search.notrustverify.ch",
|
|
|
|
"whoogle.datura.network",
|
|
|
|
"whoogle.yepserver.xyz",
|
|
|
|
"search.nezumi.party",
|
2023-01-16 16:36:14 +00:00
|
|
|
],
|
|
|
|
},
|
2024-04-19 09:31:38 +00:00
|
|
|
"biblioreads": {
|
|
|
|
"source": ["goodreads.com"],
|
|
|
|
"target": [
|
|
|
|
"biblioreads.eu.org",
|
|
|
|
"biblioreads.vercel.app",
|
|
|
|
"biblioreads.mooo.com",
|
|
|
|
"bl.vern.cc",
|
|
|
|
"biblioreads.lunar.icu",
|
|
|
|
"read.whateveritworks.org",
|
|
|
|
"biblioreads.privacyfucking.rocks",
|
|
|
|
"read.seitan-ayoub.lol",
|
|
|
|
"read.freedit.eu",
|
|
|
|
"biblioreads.ducks.party",
|
|
|
|
"biblioreads.snine.nl",
|
|
|
|
"biblioreads.privacyredirect.com",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
"safetwitch": {
|
|
|
|
"source": ["twitch.tv"],
|
|
|
|
"target": [
|
|
|
|
"safetwitch.drgns.space",
|
|
|
|
"safetwitch.projectsegfau.lt",
|
|
|
|
"stream.whateveritworks.org",
|
|
|
|
"safetwitch.datura.network",
|
|
|
|
"ttv.vern.cc",
|
|
|
|
"safetwitch.frontendfriendly.xyz",
|
|
|
|
"ttv.femboy.band",
|
|
|
|
"twitch.seitan-ayoub.lol",
|
|
|
|
"st.ggtyler.dev",
|
|
|
|
"safetwitch.lunar.icu",
|
|
|
|
"twitch.sudovanilla.com",
|
|
|
|
"safetwitch.r4fo.com",
|
|
|
|
"safetwitch.ducks.party",
|
|
|
|
"safetwitch.nogafam.fr",
|
|
|
|
"safetwitch.privacyredirect.com",
|
|
|
|
"st.ngn.tf",
|
|
|
|
],
|
|
|
|
},
|
2023-01-16 16:36:14 +00:00
|
|
|
}
|
|
|
|
|
2023-11-15 13:24:27 +00:00
|
|
|
|
2023-10-03 11:43:00 +00:00
|
|
|
def rewrite(request: interceptor.Request) -> None:
|
|
|
|
# if config.get(name="content.oss_redirects") is False:
|
|
|
|
# return
|
2023-03-22 10:48:57 +00:00
|
|
|
|
2023-01-16 16:36:14 +00:00
|
|
|
if (
|
|
|
|
request.resource_type != interceptor.ResourceType.main_frame
|
|
|
|
or request.request_url.scheme() in {"data", "blob"}
|
|
|
|
):
|
|
|
|
return
|
|
|
|
|
|
|
|
url = request.request_url
|
|
|
|
|
2023-08-29 20:45:09 +00:00
|
|
|
if service := _should_be_redirected(url.host()):
|
2024-06-27 15:35:35 +00:00
|
|
|
url = _farside_redirect(
|
|
|
|
url, _pick_random(service["farside" if "farside" in service else "target"])
|
|
|
|
)
|
2024-02-05 11:09:23 +00:00
|
|
|
try:
|
|
|
|
request.redirect(url)
|
|
|
|
except RedirectException as e:
|
|
|
|
message.error(str(e))
|
|
|
|
|
|
|
|
if "postprocess" in service and isinstance(service["postprocess"], Callable):
|
|
|
|
url = service["postprocess"](url)
|
|
|
|
|
|
|
|
|
2024-06-27 15:35:35 +00:00
|
|
|
def _farside_redirect(url: QUrl, service: str, use_fastside: bool = True) -> QUrl:
|
2024-02-05 11:09:23 +00:00
|
|
|
try:
|
2024-06-27 15:35:35 +00:00
|
|
|
url.setHost("fastside.link" if use_fastside else "farside.link")
|
2024-02-05 11:09:23 +00:00
|
|
|
url.setPath(f"/{service}{url.path()}")
|
|
|
|
except RedirectException as e:
|
|
|
|
message.error(str(e))
|
|
|
|
return url
|
|
|
|
|
|
|
|
|
2024-06-27 15:35:35 +00:00
|
|
|
def _pick_random[T](choices: list[T]) -> T:
|
2024-02-05 11:09:23 +00:00
|
|
|
return choices[random.randint(0, len(choices) - 1)]
|
|
|
|
|
|
|
|
|
|
|
|
def _should_be_redirected(
|
2024-06-27 15:35:35 +00:00
|
|
|
# TODO: Update to use typedefs/classes instead of this jumble
|
|
|
|
host: str,
|
|
|
|
redirects: Redirects = redirects,
|
|
|
|
) -> Service | None:
|
2023-01-16 16:36:14 +00:00
|
|
|
for service in redirects.values():
|
|
|
|
for source in service["source"]:
|
2023-08-29 20:45:09 +00:00
|
|
|
if re.search(source, host):
|
|
|
|
return service
|
|
|
|
return None
|
2023-01-16 16:36:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
interceptor.register(rewrite)
|