61741c9874
proxylist 1.0
67 lines
1.9 KiB
Python
Executable file
67 lines
1.9 KiB
Python
Executable file
#!/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)
|