Implement autocreation of proxy.json, removing tempout after execution

Signed-off-by: hax <hax@lainlounge.xyz>
This commit is contained in:
h@x 2025-02-09 03:01:50 +00:00
parent 3a73d9fc75
commit 3605c5a2c4

24
main.py
View file

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