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."""