huuyfytryr commited on
Commit
ff37c87
Β·
1 Parent(s): ee2a4a8

Add YT_COOKIES and YT_PROXY support for bypassing datacenter blocks

Browse files
Files changed (1) hide show
  1. app.py +20 -0
app.py CHANGED
@@ -27,6 +27,17 @@ OUTPUT_FOLDER = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'output
27
  os.makedirs(UPLOAD_FOLDER, exist_ok=True)
28
  os.makedirs(OUTPUT_FOLDER, exist_ok=True)
29
 
 
 
 
 
 
 
 
 
 
 
 
30
  # ── Background Cleanup Thread (30-minute expiration) ──
31
  def start_cleanup_thread():
32
  def cleanup_loop():
@@ -357,6 +368,15 @@ def clip_youtube_video():
357
  "-o", raw_download_path
358
  ]
359
 
 
 
 
 
 
 
 
 
 
360
  if attempt["impersonate"]:
361
  cmd.extend(["--impersonate", attempt["impersonate"]])
362
 
 
27
  os.makedirs(UPLOAD_FOLDER, exist_ok=True)
28
  os.makedirs(OUTPUT_FOLDER, exist_ok=True)
29
 
30
+ # ── Write Cookies File from Environment Variable if present ──
31
+ COOKIES_FILE_PATH = os.path.join(UPLOAD_FOLDER, 'cookies.txt')
32
+ yt_cookies_content = os.environ.get('YT_COOKIES')
33
+ if yt_cookies_content:
34
+ try:
35
+ with open(COOKIES_FILE_PATH, 'w', encoding='utf-8') as f:
36
+ f.write(yt_cookies_content.strip())
37
+ print("[startup] Successfully wrote cookies.txt from YT_COOKIES environment variable.")
38
+ except Exception as e:
39
+ print(f"[startup] Failed to write cookies.txt: {e}")
40
+
41
  # ── Background Cleanup Thread (30-minute expiration) ──
42
  def start_cleanup_thread():
43
  def cleanup_loop():
 
368
  "-o", raw_download_path
369
  ]
370
 
371
+ # Use cookies if available
372
+ if os.path.exists(COOKIES_FILE_PATH) and os.path.getsize(COOKIES_FILE_PATH) > 0:
373
+ cmd.extend(["--cookies", COOKIES_FILE_PATH])
374
+
375
+ # Use proxy if available
376
+ yt_proxy = os.environ.get('YT_PROXY')
377
+ if yt_proxy:
378
+ cmd.extend(["--proxy", yt_proxy])
379
+
380
  if attempt["impersonate"]:
381
  cmd.extend(["--impersonate", attempt["impersonate"]])
382