From 79fb7531beccdd99c3941391b4d95dee7ea1af51 Mon Sep 17 00:00:00 2001 From: Vansh Comar <69755265+vacom13@users.noreply.github.com> Date: Sat, 16 Oct 2021 23:52:00 +0530 Subject: [PATCH] Implement scribe.rip replacement for medium.com results (#463) scribe.rip is a privacy respecting front end for medium.com. This feature allows medium.com results to be replaced with scribe.rip links, and works for both regular medium.com domains as well as user specific subdomains (i.e. user.medium.com). [scribe.rip website](https://scribe.rip) [scribe.rip source code](https://git.sr.ht/~edwardloveall/scribe) Co-authored-by: Ben Busby --- Dockerfile | 2 ++ README.md | 2 ++ app.json | 5 +++++ app/utils/results.py | 10 +++++++--- docker-compose.yml | 1 + whoogle.env | 1 + 6 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 65ba191..5c925aa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -57,6 +57,8 @@ ARG reddit_alt='libredd.it' ENV WHOOGLE_ALT_RD=$reddit_alt ARG translate_alt='lingva.ml' ENV WHOOGLE_ALT_TL=$translate_alt +ARG medium_alt='scribe.rip' +ENV WHOOGLE_ALT_MD=$medium_alt WORKDIR /whoogle diff --git a/README.md b/README.md index 0fe72db..8e7a860 100644 --- a/README.md +++ b/README.md @@ -195,6 +195,7 @@ Description=Whoogle #Environment=WHOOGLE_ALT_IG=bibliogram.art/u #Environment=WHOOGLE_ALT_RD=libredd.it #Environment=WHOOGLE_ALT_TL=lingva.ml +#Environment=WHOOGLE_ALT_MD=scribe.rip # Load values from dotenv only #Environment=WHOOGLE_DOTENV=1 Type=simple @@ -312,6 +313,7 @@ There are a few optional environment variables available for customizing a Whoog | WHOOGLE_ALT_IG | The instagram.com alternative to use when site alternatives are enabled in the config. | | WHOOGLE_ALT_RD | The reddit.com alternative to use when site alternatives are enabled in the config. | | WHOOGLE_ALT_TL | The Google Translate alternative to use. This is used for all "translate ____" searches. | +| WHOOGLE_ALT_MD | The medium.com alternative to use when site alternatives are enabled in the config. | | WHOOGLE_AUTOCOMPLETE | Controls visibility of autocomplete/search suggestions. Default on -- use '0' to disable | ### Config Environment Variables diff --git a/app.json b/app.json index 791cba4..af3aad2 100644 --- a/app.json +++ b/app.json @@ -70,6 +70,11 @@ "value": "lingva.ml", "required": false }, + "WHOOGLE_ALT_MD": { + "description": "The site to use as a replacement for medium.com when site alternatives are enabled in the config.", + "value": "scribe.rip", + "required": false + }, "WHOOGLE_CONFIG_COUNTRY": { "description": "[CONFIG] The country to use for restricting search results (use values from https://raw.githubusercontent.com/benbusby/whoogle-search/develop/app/static/settings/countries.json)", "value": "", diff --git a/app/utils/results.py b/app/utils/results.py index 5a06855..60a4f6b 100644 --- a/app/utils/results.py +++ b/app/utils/results.py @@ -26,7 +26,8 @@ SITE_ALTS = { 'twitter.com': os.getenv('WHOOGLE_ALT_TW', 'nitter.net'), 'youtube.com': os.getenv('WHOOGLE_ALT_YT', 'invidious.snopyta.org'), 'instagram.com': os.getenv('WHOOGLE_ALT_IG', 'bibliogram.art/u'), - 'reddit.com': os.getenv('WHOOGLE_ALT_RD', 'libredd.it') + 'reddit.com': os.getenv('WHOOGLE_ALT_RD', 'libredd.it'), + 'medium.com': os.getenv('WHOOGLE_ALT_MD', 'scribe.rip'), } @@ -72,12 +73,15 @@ def get_site_alt(link: str) -> str: str: An updated (or ignored) result link """ + # Need to replace full hostname with alternative to encapsulate + # subdomains as well + hostname = urlparse.urlparse(link).hostname for site_key in SITE_ALTS.keys(): - if site_key not in link: + if not hostname or site_key not in hostname: continue - link = link.replace(site_key, SITE_ALTS[site_key]) + link = link.replace(hostname, SITE_ALTS[site_key]) for prefix in SKIP_PREFIX: link = link.replace(prefix, '//') break diff --git a/docker-compose.yml b/docker-compose.yml index dbb741b..52abf4d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -37,6 +37,7 @@ services: #- WHOOGLE_ALT_IG=bibliogram.art/u #- WHOOGLE_ALT_RD=libredd.it #- WHOOGLE_ALT_TL=lingva.ml + #- WHOOGLE_ALT_MD=scribe.rip #env_file: # Alternatively, load variables from whoogle.env #- whoogle.env ports: diff --git a/whoogle.env b/whoogle.env index b7c8652..c3b65f2 100644 --- a/whoogle.env +++ b/whoogle.env @@ -9,6 +9,7 @@ #WHOOGLE_ALT_IG=bibliogram.art/u #WHOOGLE_ALT_RD=libredd.it #WHOOGLE_ALT_TL=lingva.ml +#WHOOGLE_ALT_MD=scribe.rip #WHOOGLE_USER="" #WHOOGLE_PASS="" #WHOOGLE_PROXY_USER=""