v4
This commit is contained in:
1 parent
7d2bdfafc3
commit
a490152a99
2 files changed
+20
-11
No files matched your search
@@ -2,3 +2,4 @@
|
|||||||
nohup.out
|
nohup.out
|
||||||
venv
|
venv
|
||||||
downloads
|
downloads
|
||||||
|
cookies.txt
|
||||||
@@ -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.
|
||||||
|
# cachedir - persists solved JS sig/nsig to disk so node only re-runs
|
||||||
# when YouTube rotates their player (every few days).
|
# when YouTube rotates their player (every few days).
|
||||||
# • sleep_interval /
|
# http_chunk_size - 10 MB chunks; plays nicer with YouTube CDN.
|
||||||
# max_sleep_interval– small random sleep between fragment requests;
|
# js_runtimes - use local node v20+ for JS challenge solving.
|
||||||
# makes traffic pattern look more human.
|
#
|
||||||
# • http_chunk_size – stream in 10 MB chunks rather than one giant request;
|
# NOTE: sleep_interval intentionally removed — it was artificially capping
|
||||||
# reduces the chance of a mid-transfer 429.
|
# download speed. Anti-throttle measures live in the frontend instead.
|
||||||
# • js_runtimes – use local node v20+ for JS challenge solving.
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
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
|
||||||
|
|||||||
Reference in new issue
Block a user