From 3605c5a2c40ef19c55d0e3daa5013d6440f0e29a Mon Sep 17 00:00:00 2001 From: hax Date: Sun, 9 Feb 2025 03:01:50 +0000 Subject: [PATCH] Implement autocreation of proxy.json, removing tempout after execution Signed-off-by: hax --- main.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/main.py b/main.py index beb0d57..48ed466 100644 --- a/main.py +++ b/main.py @@ -93,20 +93,18 @@ def update_proxies(): def run_yt_dlp(): """Run yt-dlp with a randomly selected proxy.""" while True: - with open("proxy.json", "r") as f: - proxies = json.load(f) - if not proxies: - print("No proxies available. Please run the update command first.") - break - - proxy = random.choice(proxies) - proxy_str = construct_proxy_string(proxy) - print(f"Using proxy from {proxy['city']}, {proxy['country']}") - - if execute_yt_dlp_command(proxy_str): + try: + with open("proxy.json", "r") as f: + proxy = random.choice(json.load(f)) + proxy_str = construct_proxy_string(proxy) + print(f"Using proxy from {proxy['city']}, {proxy['country']}") + if execute_yt_dlp_command(proxy_str): + os.remove("tempout") break # Exit loop if command was successful - print("Got 'Sign in to confirm' error. Trying again with another proxy...") - time.sleep(1) # Small delay before retrying + print("Got 'Sign in to confirm' error. Trying again with another proxy...") + except FileNotFoundError as e: + print("'proxy.json' not found. Starting proxy list update...") + update_proxies() def execute_yt_dlp_command(proxy_str): """Execute the yt-dlp command with the given proxy."""