From 529cd1d3f16b59cb17e6ec66677c757b621b10b7 Mon Sep 17 00:00:00 2001 From: stabbedbybrick <125766685+stabbedbybrick@users.noreply.github.com> Date: Thu, 18 Jan 2024 15:14:35 +0100 Subject: [PATCH] Add windscribe to `--proxy` search --- utils/config.py | 2 +- utils/proxies.py | 36 ++++++++++++++++++++++++++++-------- utils/search/search.py | 6 +++++- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/utils/config.py b/utils/config.py index 9e9d327..ecbf381 100644 --- a/utils/config.py +++ b/utils/config.py @@ -115,5 +115,5 @@ class Config: ) if self.proxy != "False": - uri = get_proxy(self) + uri = get_proxy(cli=self) self.client.proxies = {"http": uri, "https": uri} diff --git a/utils/proxies.py b/utils/proxies.py index 3842ce5..dd6e497 100644 --- a/utils/proxies.py +++ b/utils/proxies.py @@ -11,7 +11,7 @@ log = logging.getLogger() class Windscribe: - def __init__(self, config: dict) -> None: + def __init__(self, username: str, password: str) -> None: self.executable = get_binary( "windscribe-proxy", "windscribe-proxy.windows-amd64", @@ -24,8 +24,8 @@ class Windscribe: self.wndstate = Path("utils") / "settings" / "wndstate.json" - self.username = config["windscribe"].get("username") - self.password = config["windscribe"].get("password") + self.username = username + self.password = password if not self.wndstate.exists() and not self.username and not self.password: raise IndexError("Windscribe credentials must be provided") @@ -115,8 +115,21 @@ class Hola: # pass -def get_proxy(cli: object, location: str = None) -> str: - client = cli.config.get("proxy") +def get_proxy( + cli: object = None, + config: dict = None, + client: str = None, + location: str = None + ) -> str: + + # client = cli.config.get("proxy") if cli else client + if cli is not None: + client = cli.config.get("proxy") + elif config is not None: + client = config.get("proxy") + elif client is not None: + client = client + if not client: raise IndexError("A proxy client must be set in config file") client = client.lower() @@ -129,7 +142,7 @@ def get_proxy(cli: object, location: str = None) -> str: return url elif client == "hola": - iso = location if location else cli.proxy + iso = cli.proxy if cli else location if not len(iso) == 2: raise ValueError("Country codes should only be two letters") @@ -141,12 +154,19 @@ def get_proxy(cli: object, location: str = None) -> str: return hola.proxy(query) elif client == "windscribe": - iso = location if location else cli.proxy + iso = cli.proxy if cli else location if not len(iso) == 2: raise ValueError("Country codes should only be two letters") + if cli is not None: + username = cli.config["windscribe"].get("username") + password = cli.config["windscribe"].get("password") + elif config is not None: + username = config["windscribe"].get("username") + password = config["windscribe"].get("password") + log.info(f"+ Adding Windscribe proxy location: {iso.upper()}") query = iso.lower() - windscribe = Windscribe(cli.config) + windscribe = Windscribe(username, password) return windscribe.proxy(query) diff --git a/utils/search/search.py b/utils/search/search.py index 1e75cae..121a90a 100644 --- a/utils/search/search.py +++ b/utils/search/search.py @@ -1,3 +1,4 @@ +import yaml import httpx from rich.console import Console @@ -14,8 +15,11 @@ class Config: if keywords: keywords = keywords.lower() + with open("config.yaml", "r") as f: + self.config = yaml.safe_load(f) + if proxy != "False": - uri = get_proxy(proxy) + uri = get_proxy(config=self.config, location=proxy) self.client = httpx.Client(proxies={"http://": uri, "https://": uri}) else: self.client = httpx.Client(