From 61741c98746455303dfa84b5b1d6309aedfe0b94 Mon Sep 17 00:00:00 2001 From: Wolfgang Nowak Date: Sun, 29 Oct 2023 10:19:21 +0100 Subject: [PATCH] tuprox.py 1.0 proxylist 1.0 --- tuprox.py | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 tuprox.py diff --git a/tuprox.py b/tuprox.py new file mode 100755 index 0000000..3548fe2 --- /dev/null +++ b/tuprox.py @@ -0,0 +1,67 @@ +#!/usr/bin/python3 + +""" +Make it some easyer to find a working invidious instance. +You should have a file names proxylist with hostnames line per line +in your homedirectory. +Put the youtube-url into clipboard, call the script and paste the new urls into your chat. +The script reads the _clipboard_, does its work and puts the result +back into the clipboard +You should make a clicko in your desktoppanel. +""" + +import os, sys, re, pyperclip, notify2 +from random import randint + +# look for a list of proxies at /home/user/proxylist +proxyfile_path = os.path.expanduser("~") + "/" + "proxylist" +proxy_list = [] + +# define browser. Firefox for president! +browser = "firefox" +browser_param = [" --new-tab "] + +# Slurp in the proxylist +with open(proxyfile_path) as proxies: + for proxy in proxies: + proxy_list.append(proxy.rstrip()) + +new_urls = [] + +# Number of proxies in proxyfile +proxy_counter = len(proxy_list) + +# Choose one by random +random_proxy = randint(0, proxy_counter - 1) + +# Get the problematic url from clipboard +youtube_url = pyperclip.paste() + +# do we have an accident without any url? My mouse is haunted... +if youtube_url.find("https://") == -1: + sys.exit("no Url found") + +# or an accident with leading trash? +youtube_url = re.sub("^.*https://", "https://", youtube_url) + +# make a list of urls with the replaced servers +# and print a list for convenience +for count in range(0, proxy_counter): + new_urls.append(re.sub("^.*://.*/", "https://" + proxy_list[count] + "/", youtube_url)) + print(new_urls[count]) + + +# put the chosen proxy into clipboard + +pyperclip.copy(new_urls[random_proxy] + "\n") + +# Send some notification to desktoptray +notify2.init(sys.argv[0]) +n = notify2.Notification(new_urls[random_proxy], "").show() +notify2.uninit() + +# execvp wants its parameters as a tuple +browser_param.append(new_urls[random_proxy]) + +# startup browser with a new tab +# os.execvp(browser, browser_param)