Add cookies file support for Docker; auto-detect /data/cookies.txt

This commit is contained in:
inputnoise
2026-05-25 20:57:04 +02:00
parent bcc425b6fb
commit 56dd5f8360
5 changed files with 48 additions and 2 deletions

View File

@@ -401,8 +401,11 @@ def predicted_file_path(video_id: str) -> Path:
_SEMAPHORE = threading.Semaphore(3)
_semaphore_lock = threading.Lock()
_cookies_browser: str = ""
_cookies_file: str = ""
_cookies_lock = threading.Lock()
_AUTO_COOKIES_PATHS = ["/data/cookies.txt"]
def set_max_concurrent(n: int) -> None:
global _SEMAPHORE
@@ -416,10 +419,27 @@ def set_cookies_browser(browser: str) -> None:
_cookies_browser = browser.strip().lower()
def set_cookies_file(path: str) -> None:
global _cookies_file
with _cookies_lock:
_cookies_file = path.strip()
def _cookie_args() -> list[str]:
with _cookies_lock:
cf = _cookies_file
b = _cookies_browser
return ["--cookies-from-browser", b] if b else []
# Prefer explicit cookies file
if cf and Path(cf).exists():
return ["--cookies", cf]
# Auto-detect cookies.txt in well-known Docker locations
for candidate in _AUTO_COOKIES_PATHS:
if Path(candidate).exists():
return ["--cookies", candidate]
# Fall back to browser (works in local dev, not in Docker)
if b:
return ["--cookies-from-browser", b]
return []
def start_download(