2023-01-16 16:36:14 +00:00
|
|
|
import random
|
2023-08-29 20:45:09 +00:00
|
|
|
from urllib import parse
|
2023-01-16 16:36:14 +00:00
|
|
|
import re
|
|
|
|
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
|
|
|
|
|
|
|
redirects = {
|
|
|
|
"youtube": {
|
|
|
|
"source": ["youtube.com"],
|
|
|
|
"target": [
|
2023-11-15 13:24:27 +00:00
|
|
|
"invidious.no-logs.com",
|
|
|
|
"inv.citw.lgbt",
|
|
|
|
"invidious.privacydev.net",
|
|
|
|
"inv.tux.pizza",
|
|
|
|
"invidious.einfachzocken.eu",
|
|
|
|
"invidious.perennialte.ch",
|
|
|
|
"invidious.fdn.fr",
|
2023-01-16 16:36:14 +00:00
|
|
|
"invidious.nerdvpn.de",
|
2023-11-15 13:24:27 +00:00
|
|
|
"inv.zzls.xyz",
|
|
|
|
"invidious.private.coffee",
|
|
|
|
"invidious.projectsegfau.lt",
|
|
|
|
"invidious.lunar.icu",
|
2023-01-16 16:36:14 +00:00
|
|
|
"yewtu.be",
|
2023-11-15 13:24:27 +00:00
|
|
|
"iv.melmac.space",
|
|
|
|
"iv.datura.network",
|
2023-12-04 07:38:35 +00:00
|
|
|
"piped.kavin.rocks",
|
2023-01-16 16:36:14 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
"lbry": {
|
|
|
|
"source": ["odysee.com"],
|
|
|
|
"target": [
|
|
|
|
"lbry.bcow.xyz",
|
|
|
|
"odysee.076.ne.jp",
|
|
|
|
"librarian.pussthecat.org",
|
|
|
|
"lbry.mutahar.rocks",
|
|
|
|
"lbry.vern.cc",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
"reddit": {
|
|
|
|
"source": ["reddit.com"],
|
|
|
|
"target": [
|
2023-12-04 07:38:35 +00:00
|
|
|
"teddit.ggc-project.de",
|
|
|
|
"teddit.kavin.rocks",
|
2023-01-16 16:36:14 +00:00
|
|
|
"teddit.zaggy.nl",
|
2023-12-04 07:38:35 +00:00
|
|
|
"teddit.namazso.eu",
|
|
|
|
"teddit.nautolan.racing",
|
|
|
|
"teddit.tinfoil-hat.net",
|
|
|
|
"teddit.domain.glass",
|
|
|
|
"libreddit.kavin.rocks",
|
|
|
|
"safereddit.com",
|
|
|
|
"reddit.invak.id",
|
|
|
|
"reddit.simo.sh",
|
|
|
|
"libreddit.strongthany.cc",
|
|
|
|
"libreddit.domain.glass",
|
|
|
|
"libreddit.pussthecat.org",
|
|
|
|
"libreddit.kylrth.com",
|
|
|
|
"libreddit.privacydev.net",
|
|
|
|
"l.opnxng.com",
|
|
|
|
"libreddit.oxymagnesium.com",
|
|
|
|
"reddit.utsav2.dev",
|
|
|
|
"libreddit.freedit.eu",
|
|
|
|
"lr.artemislena.eu",
|
|
|
|
"snoo.habedieeh.re",
|
2023-01-16 16:36:14 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
"twitter": {
|
|
|
|
"source": ["twitter.com"],
|
|
|
|
"target": [
|
|
|
|
"nitter.net",
|
|
|
|
"nitter.42l.fr",
|
|
|
|
"nitter.fdn.fr",
|
|
|
|
"nitter.1d4.us",
|
|
|
|
"nitter.kavin.rocks",
|
|
|
|
"nitter.unixfox.eu",
|
|
|
|
"nitter.namazso.eu",
|
|
|
|
"nitter.moomoo.me",
|
|
|
|
"bird.trom.tf",
|
|
|
|
"nitter.it",
|
|
|
|
"twitter.censors.us",
|
|
|
|
"nitter.grimneko.de",
|
|
|
|
"twitter.076.ne.jp",
|
|
|
|
"n.l5.ca",
|
|
|
|
"unofficialbird.com",
|
|
|
|
"nitter.ungovernable.men",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
"imdb": {
|
|
|
|
"source": ["imdb.com"],
|
|
|
|
"target": [
|
|
|
|
"libremdb.iket.me",
|
|
|
|
"libremdb.pussthecat.org",
|
|
|
|
"ld.vern.cc",
|
|
|
|
"binge.whatever.social",
|
|
|
|
"libremdb.lunar.icu",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
"translate": {
|
|
|
|
"source": ["translate.google.com"],
|
|
|
|
"target": [
|
|
|
|
"lingva.ml",
|
|
|
|
"translate.igna.wtf",
|
|
|
|
"translate.plausibility.cloud",
|
|
|
|
"translate.projectsegfau.lt",
|
|
|
|
"translate.dr460nf1r3.org",
|
|
|
|
"lingva.garudalinux.org",
|
|
|
|
"translate.jae.fi",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
"tiktok": {
|
|
|
|
"source": ["tiktok.com"],
|
|
|
|
"target": [
|
|
|
|
"proxitok.pabloferreiro.es",
|
|
|
|
"proxitok.pussthecat.org",
|
|
|
|
"tok.habedieeh.re",
|
|
|
|
"proxitok.privacydev.net",
|
|
|
|
"proxitok.odyssey346.dev",
|
|
|
|
"tok.artemislena.eu",
|
|
|
|
"tok.adminforge.de",
|
|
|
|
"proxitok.manasiwibi.com",
|
|
|
|
"tik.hostux.net",
|
|
|
|
"tt.vern.cc",
|
|
|
|
"proxitok.mha.fi",
|
|
|
|
"proxitok.pufe.org",
|
|
|
|
"proxitok.marcopisco.com",
|
|
|
|
"cringe.whatever.social",
|
|
|
|
"proxitok.lunar.icu",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
"imgur": {
|
|
|
|
"source": ["imgur.com"],
|
|
|
|
"target": [
|
|
|
|
"imgur.artemislena.eu",
|
|
|
|
"ri.zzls.xyz",
|
2023-06-22 10:08:52 +00:00
|
|
|
"rimgo.bus-hit.me",
|
|
|
|
"rimgo.fascinated.cc",
|
|
|
|
"rimgo.hostux.net",
|
|
|
|
"rimgo.kling.gg",
|
2023-01-16 16:36:14 +00:00
|
|
|
"rimgo.lunar.icu",
|
2023-06-22 10:08:52 +00:00
|
|
|
"rimgo.marcopisco.com",
|
|
|
|
"rimgo.privacytools.io",
|
|
|
|
"rimgo.projectsegfau.lt",
|
|
|
|
"rimgo.pussthecat.org",
|
|
|
|
"rimgo.totaldarkness.net",
|
|
|
|
"rimgo.whateveritworks.org",
|
2023-01-16 16:36:14 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
"medium": {
|
|
|
|
"source": ["medium.com"],
|
|
|
|
"target": [
|
|
|
|
"scribe.rip",
|
|
|
|
"scribe.citizen4.eu",
|
|
|
|
"scribe.bus-hit.me",
|
|
|
|
"sc.vern.cc",
|
|
|
|
],
|
2023-08-29 20:45:09 +00:00
|
|
|
"postprocess": fixScribePath,
|
2023-01-16 16:36:14 +00:00
|
|
|
},
|
|
|
|
"google": {
|
|
|
|
"source": ["google.com"],
|
|
|
|
"target": [
|
|
|
|
"whoogle.dcs0.hu",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
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()):
|
|
|
|
# TODO integrate pinging and always surf to fastest?
|
|
|
|
target = service["target"][random.randint(0, len(service["target"]) - 1)]
|
|
|
|
if target is not None and url.setHost(target) is not False:
|
|
|
|
if "postprocess" in service:
|
|
|
|
url = service["postprocess"](url)
|
|
|
|
try:
|
|
|
|
request.redirect(url)
|
|
|
|
except RedirectException as e:
|
|
|
|
message.error(str(e))
|
|
|
|
|
|
|
|
|
|
|
|
def _should_be_redirected(host: str, redirects: dict = redirects) -> dict | 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)
|