yb.download.requirements¶
Preflight for downloading: does yt-dlp have what YouTube now demands?
YouTube makes yt-dlp solve a JavaScript “n challenge”. Without a solver it
fails late and cryptically (No video formats found!). Solving needs two
things:
yt-dlp’s challenge-solver scripts, shipped by
yt-dlp[default](theyt-dlp-ejspackage), whichyb[download]depends on;a JavaScript runtime. Deno is the one yt-dlp enables by default, and the one that works.
Deno’s installer puts it in ~/.deno/bin and only adds that to PATH for
interactive shells, so a cron job or service often can’t see it. This module
also looks there, and yt_dlp_runtime_opts() hands yt-dlp the explicit
path, so downloads work without touching PATH.
>>> from yb.download import check_requirements
>>> problems = check_requirements()
>>> print("\n\n".join(problems) or "ready")
Nothing here raises: missing pieces are reported (and, by default, warned) with the command that fixes them.
Module Attributes
The JavaScript runtime yt-dlp enables by default, and the one that works. |
|
Deno's official installer. |
|
Env var Deno's installer honours for its install root (binary in |
|
yt-dlp's import name. |
|
Module that carries yt-dlp's challenge-solver scripts (from |
|
Command that brings an installed Deno up to date. |
|
Fallback for Deno's minimum version when yt-dlp can't be asked (not importable, or too old to say). |
|
Seconds to wait for |
|
yt-dlp's notes on the JavaScript challenge. |
|
The yt-dlp option naming JS runtimes ( |
Functions
|
Check what YouTube downloads need, and say how to fix what's missing. |
Where Deno lives when it isn't on |
|
|
Ask |
|
Find Deno on |
|
Whether yt-dlp's challenge-solver scripts ( |
|
Whether module |
|
The oldest Deno yt-dlp supports, as a version tuple. |
|
|
|
yt-dlp options pointing at |
Classes
|
A JavaScript runtime found for yt-dlp. |
Exceptions
A download prerequisite (JS runtime, solver scripts) looks missing. |
- yb.download.requirements.DENO = 'deno'¶
The JavaScript runtime yt-dlp enables by default, and the one that works.
- yb.download.requirements.DENO_INSTALL_CMD = 'curl -fsSL https://deno.land/install.sh | sh'¶
Deno’s official installer.
- yb.download.requirements.DENO_INSTALL_ENV = 'DENO_INSTALL'¶
Env var Deno’s installer honours for its install root (binary in
<root>/bin).
- yb.download.requirements.DENO_MIN_VERSION_FALLBACK = (2, 3, 0)¶
Fallback for Deno’s minimum version when yt-dlp can’t be asked (not importable, or too old to say). yt-dlp’s own value wins: see
min_deno_version().
- yb.download.requirements.DENO_UPGRADE_CMD = 'deno upgrade'¶
Command that brings an installed Deno up to date.
- yb.download.requirements.DENO_VERSION_TIMEOUT = 10¶
Seconds to wait for
deno --version.
- exception yb.download.requirements.DownloadRequirementWarning[source]¶
Bases:
UserWarningA download prerequisite (JS runtime, solver scripts) looks missing.
- yb.download.requirements.EJS_MODULE = 'yt_dlp_ejs'¶
Module that carries yt-dlp’s challenge-solver scripts (from
yt-dlp[default]).
- yb.download.requirements.EJS_WIKI_URL = 'https://github.com/yt-dlp/yt-dlp/wiki/EJS'¶
yt-dlp’s notes on the JavaScript challenge.
- yb.download.requirements.JS_RUNTIMES_OPT = 'js_runtimes'¶
The yt-dlp option naming JS runtimes (
{"deno": {"path": ...}}).
- class yb.download.requirements.JsRuntime(name, path, on_path)[source]¶
Bases:
objectA JavaScript runtime found for yt-dlp.
- name¶
yt-dlp’s key for the runtime (e.g.
"deno").
- path¶
The executable.
- on_path¶
Whether yt-dlp would find it by name on
PATHunaided.
- yb.download.requirements.YT_DLP_MODULE = 'yt_dlp'¶
yt-dlp’s import name.
- yb.download.requirements.check_requirements(*, warn=True, which=<function which>, search_dirs=None, find_spec=<function find_spec>, run=<function run>, import_module=<function import_module>, check_deno_version=True)[source]¶
Check what YouTube downloads need, and say how to fix what’s missing.
Never raises. Each problem is a message ending with the fix.
- Parameters:
warn (
bool) – Also emit each problem as aDownloadRequirementWarning.which (
Callable[[str],str|None]) – Seefind_js_runtime().search_dirs (
Iterable[Path] |None) – Seefind_js_runtime().find_spec (
Callable[[str],object|None]) – Module lookup forhas_module().run (
Callable[...,CompletedProcess[str]]) – Subprocess runner fordeno_version().import_module (
Callable[[str],object]) – Importer formin_deno_version().check_deno_version (
bool) – Also rundeno --versionand compare it with yt-dlp’s minimum. The download preflight turns this off: it spawns a process, which belongs in an explicit check, not in a download.
- Return type:
- Returns:
The problems found; empty when downloads should work.
- yb.download.requirements.deno_search_dirs()[source]¶
Where Deno lives when it isn’t on
PATH.This Python’s scripts dir and its interpreter’s dir (a pip-installed Deno, e.g.
yt-dlp[deno], in a venv that isn’t activated: yt-dlp looks there too), then the installer’s$DENO_INSTALL/binand~/.deno/bin.
- yb.download.requirements.deno_version(runtime, *, run=<function run>)[source]¶
Ask
runtimefor its version (deno --version);Noneif unknown.Never raises: a runtime that can’t be run, or prints something unexpected, has an unknown version (which
check_requirements()doesn’t flag).
- yb.download.requirements.find_js_runtime(*, which=<function which>, search_dirs=None)[source]¶
Find Deno on
PATH, else in its standard install location.
- yb.download.requirements.has_ejs_scripts(*, find_spec=<function find_spec>)[source]¶
Whether yt-dlp’s challenge-solver scripts (
yt-dlp-ejs) are installed.- Return type:
- yb.download.requirements.has_module(name, *, find_spec=<function find_spec>)[source]¶
Whether module
nameis importable, without importing it.- Return type:
- yb.download.requirements.min_deno_version(*, import_module=<function import_module>)[source]¶
The oldest Deno yt-dlp supports, as a version tuple.
Read from yt-dlp (
DenoJsRuntime.MIN_SUPPORTED_VERSION) so it follows yt-dlp’s upgrades;DENO_MIN_VERSION_FALLBACKwhen yt-dlp isn’t importable or doesn’t say.
- yb.download.requirements.with_runtime_opts(opts)[source]¶
optsplus the preflight’s runtime path, unlessoptsnames runtimes.The first call per process runs
check_requirements()(warning, never raising). An explicitjs_runtimesinoptsalways wins, and skips the check: the caller has chosen a runtime.- Return type: