Last active
February 8, 2024 03:11
-
-
Save Mibo5354/cf265bc2108edb839e3607d9c9359dfa to your computer and use it in GitHub Desktop.
Windscribe Ephemeral Port Script automatically set qBittorrent listening port
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
from selenium import webdriver | |
import selenium | |
from selenium.webdriver.chrome.options import Options | |
chrome_options = Options() | |
#Configuration | |
#Windscribe cookies file path | |
cookiesfile = "/home/ubuntu/.windscribe-session.pkl" | |
#Windscribe username | |
username = "username" | |
#Windscribe password | |
password = "password" | |
#Qbittorrent | |
qbithost = "https://qbit.example.com" | |
qbitport = "443" | |
qbituser = "username" | |
qbitpass = "password" | |
import time | |
#print current date/time | |
import datetime | |
now = datetime.datetime.now() | |
print (now.strftime("%Y-%m-%d %H:%M:%S")) | |
import qbittorrentapi | |
import certifi | |
import urllib3 | |
http = urllib3.PoolManager( | |
cert_reqs="CERT_REQUIRED", | |
ca_certs=certifi.where() | |
) | |
#Required for running chromedriver headless | |
chrome_options.add_argument("--disable-gpu") | |
#chrome_options.add_argument("--no-sandbox") # linux only | |
chrome_options.add_argument("--headless") | |
from selenium.webdriver.common.keys import Keys | |
# Creating an instance webdriver | |
browser = webdriver.Chrome(options=chrome_options) | |
browser.get('https://www.windscribe.com/') | |
#load cookies | |
import pickle | |
def save_cookie(browser, path): | |
with open(path, 'wb') as filehandler: | |
pickle.dump(browser.get_cookies(), filehandler) | |
def load_cookie(browser, path): | |
with open(path, 'rb') as cookiesfile: | |
cookies = pickle.load(cookiesfile) | |
for cookie in cookies: | |
browser.add_cookie(cookie) | |
try: | |
load_cookie(browser,cookiesfile) | |
except Exception as e: | |
print (str(e)) | |
print ("Error loading cookies") | |
def is_windscribe_logged_in(): | |
browser.get("https://windscribe.com/myaccount") | |
if 'Login - Windscribe' in browser.title: | |
return False | |
else: | |
return True | |
if is_windscribe_logged_in(): | |
print("Already logged in") | |
else: | |
print("Not logged in") | |
browser.get('https://www.windscribe.com/login') | |
time.sleep(2) | |
print("Login to Windscribe") | |
user = browser.find_element("xpath", '//*[@id="username"]') | |
# Enter User Name | |
user.send_keys(username) | |
passw = browser.find_element("xpath", '//*[@id="pass"]') | |
# Enter and Submit Password | |
passw.send_keys(password) | |
passw.submit() | |
print("Login Successful") | |
save_cookie(browser,cookiesfile) | |
print("Saved cookies") | |
time.sleep(5) | |
browser.get('https://windscribe.com') | |
time.sleep(5) | |
browser.get('https://windscribe.com/myaccount#porteph') | |
print("Load Request Ephemeral Port Page") | |
time.sleep(5) | |
print("") | |
delPort = browser.find_element("xpath", '//*[@id="request-port-cont"]/button') | |
delPort.click() | |
print("Delete Port") | |
time.sleep(5) | |
reqMatchPort = browser.find_element("xpath", '//*[@id="request-port-cont"]/button[2]') | |
reqMatchPort.click() | |
print("Request New Port") | |
time.sleep(5) | |
port = browser.find_element("xpath", '//*[@id="epf-port-info"]/span[1]') | |
print("New Port: " + port.text) | |
aquiredPort = port.text | |
# print("Saving to port.txt") | |
# with open("port.txt", "w") as text_file: | |
# print(aquiredPort, file=text_file) | |
# closing the browser | |
browser.close() | |
# instantiate a Client using the appropriate WebUI configuration | |
client = qbittorrentapi.Client(host=qbithost, port=qbitport, username=qbituser, password=qbitpass) | |
# the Client will automatically acquire/maintain a logged in state in line with any request. | |
# therefore, this is not necessary; however, you many want to test the provided login credentials. | |
try: | |
client.auth_log_in() | |
except qbittorrentapi.LoginFailed as e: | |
print(e) | |
# display qBittorrent info | |
# print(f'qBittorrent: {client.app.version}') | |
# print(f'qBittorrent Web API: {client.app.web_api_version}') | |
#Set qBittorrent listening port | |
prefs = client.application.preferences | |
prefs['listen_port'] = aquiredPort | |
client.app.preferences = prefs | |
print("Set qBittorrent listening port to " + aquiredPort) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Created a fork, which works with updated versions of selenium.
Also created a repo https://github.com/JNuggets/Windscribe-Ephemeral-Port-Script, providing credit to the original script here