import random import re from qutebrowser.api import interceptor from qutebrowser.extensions.interceptors import RedirectException from qutebrowser.utils import message def fixScribePath(url): """ Fix external medium blog to scribe translation. 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. """ new_path = f"{url.path()}{url.query()}" url.setQuery("") url.setPath(re.sub(r"m/global-identity-2redirectUrl=", "", new_path)) redirects = { "youtube": { "source": ["youtube.com"], "target": [ "piped.thedroth.rocks", ], }, "lbry": { "source": ["odysee.com"], "target": [ "lbry.bcow.xyz", "odysee.076.ne.jp", "librarian.pussthecat.org", "lbry.mutahar.rocks", "lbry.vern.cc", ], }, "imdb": { "source": ["imdb.com"], "target": [ "libremdb.iket.me", "libremdb.pussthecat.org", "ld.vern.cc", "binge.whatever.social", "libremdb.lunar.icu", ], }, "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", "rimgo.bus-hit.me", "rimgo.fascinated.cc", "rimgo.hostux.net", "rimgo.kling.gg", "rimgo.lunar.icu", "rimgo.marcopisco.com", "rimgo.privacytools.io", "rimgo.projectsegfau.lt", "rimgo.pussthecat.org", "rimgo.totaldarkness.net", "rimgo.whateveritworks.org", ], }, "medium": { "source": ["medium.com"], "target": [ "scribe.rip", "scribe.nixnet.services", "scribe.citizen4.eu", "scribe.bus-hit.me", "scribe.froth.zone", "scribe.privacydev.net", "sc.vern.cc", ], "postprocess": fixScribePath }, "google": { "source": ["google.com"], "target": [ "whoogle.dcs0.hu", ], }, "wiki-en": { "source": ["en.wikipedia.org"], "target": [ "wiki.thedroth.rocks", ], }, "wiki-ru": { "source": ["ru.wikipedia.org"], "target": [ "wiki.thedroth.rocks", ], }, } def rewrite(request: interceptor.Request): if ( request.resource_type != interceptor.ResourceType.main_frame or request.request_url.scheme() in {"data", "blob"} ): return url = request.request_url for service in redirects.values(): matched = False for source in service["source"]: if re.search(source, url.host()): matched = True if matched: 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: service["postprocess"](url) try: request.redirect(url) except RedirectException as e: message.error(str(e)) break interceptor.register(rewrite)