Last active
February 19, 2024 15:37
-
-
Save louisroyer/a3dd8ce3d1488d4b170cd808eb7e9edc to your computer and use it in GitHub Desktop.
Makes dpgmedia URLs readable, and remove tracking parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# https://fr.wikipedia.org/wiki/Wikipédia:Bulletin_des_patrouilleurs#myprivacy.dpgmedia.be | |
import sys | |
from urllib.parse import urlparse | |
from urllib.parse import parse_qsl | |
if len(sys.argv) < 2: | |
raise Exception("2nd argument must be present with the URL") | |
srcurl = sys.argv[1] | |
p = urlparse(srcurl) | |
redirect = urlparse(dict(parse_qsl(p.query))['callbackUrl']) | |
dic_redirectUri = dict(parse_qsl(redirect.query)) | |
if 'redirectUri' in dic_redirectUri: | |
redirectUri = dic_redirectUri['redirectUri'] | |
elif 'originalUrl' in dic_redirectUri: | |
redirectUri = dic_redirectUri['originalUrl'] | |
full = urlparse(redirect.scheme + '://' + redirect.netloc + redirectUri)._replace(query='').geturl() | |
print(full) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment