This commit is contained in:
alejo committed 2026-03-21 02:49:51 -03:00
1 parent 7d2bdfafc3
commit a490152a99
2 files changed
+21 -12

No files matched your search

+20 -12
View File
@@ -53,31 +53,39 @@ _USER_AGENTS = [
def _random_ua():
return random.choice(_USER_AGENTS)
# ---------------------------------------------------------------------------
# Cookies file — place a cookies.txt (Netscape format, exported from your
# browser while logged into YouTube) next to app.py to authenticate requests.
# Authenticated sessions are routed to faster CDN endpoints and bypass the
# throttling YouTube applies to anonymous traffic.
# The file is optional; if absent yt-dlp falls back to anonymous mode.
# ---------------------------------------------------------------------------
COOKIES_FILE = os.path.join(os.path.dirname(__file__), "cookies.txt")
# ---------------------------------------------------------------------------
# Base yt-dlp options shared by all calls.
#
# • cachedir – persists solved JS sig/nsig to disk; node only re-runs
# when YouTube rotates their player (every few days).
# • sleep_interval /
# max_sleep_interval– small random sleep between fragment requests;
# makes traffic pattern look more human.
# • http_chunk_size – stream in 10 MB chunks rather than one giant request;
# reduces the chance of a mid-transfer 429.
# • js_runtimes – use local node v20+ for JS challenge solving.
# cookiefile - browser cookies for authenticated (fast) CDN routing.
# cachedir - persists solved JS sig/nsig to disk so node only re-runs
# when YouTube rotates their player (every few days).
# http_chunk_size - 10 MB chunks; plays nicer with YouTube CDN.
# js_runtimes - use local node v20+ for JS challenge solving.
#
# NOTE: sleep_interval intentionally removed — it was artificially capping
# download speed. Anti-throttle measures live in the frontend instead.
# ---------------------------------------------------------------------------
def _base_opts(extra=None):
opts = {
"quiet": True,
"cachedir": CACHE_DIR,
"js_runtimes": {"node": {"executable": "/usr/bin/node"}},
"http_headers": {"User-Agent": _random_ua()},
"sleep_interval": 1,
"max_sleep_interval": 3,
"http_chunk_size": 10 * 1024 * 1024, # 10 MB
"http_chunk_size": 10 * 1024 * 1024,
"socket_timeout": 30,
"retries": 6,
"fragment_retries": 6,
}
if os.path.isfile(COOKIES_FILE):
opts["cookiefile"] = COOKIES_FILE
if extra:
opts.update(extra)
return opts