Skip to content

A feature-rich command-line audio/video downloader

Allow `--js-runtimes` to accept path to binary or directory (#14964)

bashonly4b4223b436fb
diff --git a/README.md b/README.md
index 6366c5d4c6..d4211b4b0c 100644
--- a/README.md
+++ b/README.md
@@ -369,17 +369,19 @@ Tip: Use `CTRL`+`F` (or `Command`+`F`) to search by keywords
including defaults and those provided by
previous --plugin-dirs
--js-runtimes RUNTIME[:PATH] Additional JavaScript runtime to enable,
- with an optional path to the runtime
- location. This option can be used multiple
- times to enable multiple runtimes. Supported
- runtimes are (in order of priority, from
- highest to lowest): deno, node, quickjs,
- bun. Only "deno" is enabled by default. The
- highest priority runtime that is both
- enabled and available will be used. In order
- to use a lower priority runtime when "deno"
- is available, --no-js-runtimes needs to be
- passed before enabling other runtimes
+ with an optional location for the runtime
+ (either the path to the binary or its
+ containing directory). This option can be
+ used multiple times to enable multiple
+ runtimes. Supported runtimes are (in order
+ of priority, from highest to lowest): deno,
+ node, quickjs, bun. Only "deno" is enabled
+ by default. The highest priority runtime
+ that is both enabled and available will be
+ used. In order to use a lower priority
+ runtime when "deno" is available, --no-js-
+ runtimes needs to be passed before enabling
+ other runtimes
--no-js-runtimes Clear JavaScript runtimes to enable,
including defaults and those provided by
previous --js-runtimes
diff --git a/yt_dlp/options.py b/yt_dlp/options.py
index 6315ef8a9a..96c3a8a5d1 100644
--- a/yt_dlp/options.py
+++ b/yt_dlp/options.py
@@ -466,7 +466,8 @@ def create_parser():
callback_kwargs={'delim': None},
default=['deno'],
help=(
- 'Additional JavaScript runtime to enable, with an optional path to the runtime location. '
+ 'Additional JavaScript runtime to enable, with an optional location for the runtime '
+ '(either the path to the binary or its containing directory). '
'This option can be used multiple times to enable multiple runtimes. '
'Supported runtimes are (in order of priority, from highest to lowest): deno, node, quickjs, bun. '
'Only "deno" is enabled by default. The highest priority runtime that is both enabled and '
diff --git a/yt_dlp/utils/_jsruntime.py b/yt_dlp/utils/_jsruntime.py
index 6ee299fde1..bd8fd1f880 100644
--- a/yt_dlp/utils/_jsruntime.py
+++ b/yt_dlp/utils/_jsruntime.py
@@ -2,6 +2,7 @@ from __future__ import annotations
import abc
import dataclasses
import functools
+import os.path
from ._utils import _get_exe_version_output, detect_exe_version, int_or_none
@@ -12,6 +13,14 @@ def runtime_version_tuple(v):
return tuple(int_or_none(x, default=0) for x in v.split('.'))
+def _determine_runtime_path(path, basename):
+ if not path:
+ return basename
+ if os.path.isdir(path):
+ return os.path.join(path, basename)
+ return path
+
+
@dataclasses.dataclass(frozen=True)
class JsRuntimeInfo:
name: str
@@ -38,7 +47,7 @@ class DenoJsRuntime(JsRuntime):
MIN_SUPPORTED_VERSION = (2, 0, 0)
def _info(self):
- path = self._path or 'deno'
+ path = _determine_runtime_path(self._path, 'deno')
out = _get_exe_version_output(path, ['--version'])
if not out:
return None
@@ -53,7 +62,7 @@ class BunJsRuntime(JsRuntime):
MIN_SUPPORTED_VERSION = (1, 0, 31)
def _info(self):
- path = self._path or 'bun'
+ path = _determine_runtime_path(self._path, 'bun')
out = _get_exe_version_output(path, ['--version'])
if not out:
return None
@@ -68,7 +77,7 @@ class NodeJsRuntime(JsRuntime):
MIN_SUPPORTED_VERSION = (20, 0, 0)
def _info(self):
- path = self._path or 'node'
+ path = _determine_runtime_path(self._path, 'node')
out = _get_exe_version_output(path, ['--version'])
if not out:
return None
@@ -83,7 +92,7 @@ class QuickJsRuntime(JsRuntime):
MIN_SUPPORTED_VERSION = (2023, 12, 9)
def _info(self):
- path = self._path or 'qjs'
+ path = _determine_runtime_path(self._path, 'qjs')
# quickjs does not have --version and --help returns a status code of 1
out = _get_exe_version_output(path, ['--help'], ignore_return_code=True)
if not out: