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

+1
View File
@@ -2,3 +2,4 @@
nohup.out nohup.out
venv venv
downloads downloads
cookies.txt
+20 -12
View File
@@ -53,31 +53,39 @@ _USER_AGENTS = [
def _random_ua(): def _random_ua():
return random.choice(_USER_AGENTS) 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. # Base yt-dlp options shared by all calls.
# #
# • cachedir – persists solved JS sig/nsig to disk; node only re-runs # cookiefile - browser cookies for authenticated (fast) CDN routing.
# when YouTube rotates their player (every few days). # cachedir - persists solved JS sig/nsig to disk so node only re-runs
# • sleep_interval / # when YouTube rotates their player (every few days).
# max_sleep_interval– small random sleep between fragment requests; # http_chunk_size - 10 MB chunks; plays nicer with YouTube CDN.
# makes traffic pattern look more human. # js_runtimes - use local node v20+ for JS challenge solving.
# • http_chunk_size – stream in 10 MB chunks rather than one giant request; #
# reduces the chance of a mid-transfer 429. # NOTE: sleep_interval intentionally removed — it was artificially capping
# • js_runtimes – use local node v20+ for JS challenge solving. # download speed. Anti-throttle measures live in the frontend instead.
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
def _base_opts(extra=None): def _base_opts(extra=None):
opts = { opts = {
"quiet": True,
"cachedir": CACHE_DIR, "cachedir": CACHE_DIR,
"js_runtimes": {"node": {"executable": "/usr/bin/node"}}, "js_runtimes": {"node": {"executable": "/usr/bin/node"}},
"http_headers": {"User-Agent": _random_ua()}, "http_headers": {"User-Agent": _random_ua()},
"sleep_interval": 1, "http_chunk_size": 10 * 1024 * 1024,
"max_sleep_interval": 3,
"http_chunk_size": 10 * 1024 * 1024, # 10 MB
"socket_timeout": 30, "socket_timeout": 30,
"retries": 6, "retries": 6,
"fragment_retries": 6, "fragment_retries": 6,
} }
if os.path.isfile(COOKIES_FILE):
opts["cookiefile"] = COOKIES_FILE
if extra: if extra:
opts.update(extra) opts.update(extra)
return opts return opts