Give your AI agent eyes to see the entire internet. Read & search Twitter, Reddit, YouTube, GitHub, Bilibili, XiaoHongShu — one CLI, zero API fees.
Python agent-infrastructureai-agentai-searchautomationbilibiliclaude-codeclicursorfree-apillm-toolsmcppythonreddit-scrapertwitter-scraperweb-scraperxiaohongshuyoutube-transcript
fix(youtube): align yt-dlp runtime support
Pnant9f311724ffca
diff --git a/agent_reach/channels/youtube.py b/agent_reach/channels/youtube.pyindex 69393ca8..b2601112 100644--- a/agent_reach/channels/youtube.py+++ b/agent_reach/channels/youtube.py@@ -1,6 +1,7 @@# -*- coding: utf-8 -*-"""YouTube — check if yt-dlp is available with JS runtime."""+import reimport shutilfrom agent_reach.probe import probe_command@@ -9,6 +10,14 @@ from agent_reach.utils.text import read_utf8_textfrom .base import Channel+_JS_RUNTIMES_SUPPORTED_FROM = (2025, 11, 12)+++def _parse_ytdlp_version(version: str):+ """Return a comparable stable yt-dlp release tuple, if recognised."""+ match = re.fullmatch(r"\s*(\d{4})\.(\d{1,2})\.(\d{1,2})\s*", version)+ return tuple(map(int, match.groups())) if match else None+def _has_js_runtime_config(config_path) -> bool:"""Return whether yt-dlp config explicitly enables a JS runtime."""@@ -60,6 +69,18 @@ class YouTubeChannel(Channel):if not has_deno:ytdlp_config = get_ytdlp_config_path()if not _has_js_runtime_config(ytdlp_config):+ version = _parse_ytdlp_version(probe.output)+ if version is None:+ return "warn", (+ "无法确认 yt-dlp 版本是否支持 JS runtime 配置。"+ "请先升级并重新运行 doctor:\n"+ " python -m pip install -U yt-dlp"+ )+ if version < _JS_RUNTIMES_SUPPORTED_FROM:+ return "warn", (+ "yt-dlp 版本过旧,不支持 JS runtime 配置。请先升级并重新运行 doctor:\n"+ " python -m pip install -U yt-dlp"+ )return "warn", (f"yt-dlp 已安装但未配置 JS runtime。运行:\n {render_ytdlp_fix_command()}")@@ -88,4 +109,3 @@ class YouTubeChannel(Channel):from agent_reach.transcribe import transcribe as _transcribereturn _transcribe(url, provider=provider, config=config)-diff --git a/agent_reach/utils/paths.py b/agent_reach/utils/paths.pyindex 727c70ab..8344a9c6 100644--- a/agent_reach/utils/paths.py+++ b/agent_reach/utils/paths.py@@ -3,6 +3,7 @@from __future__ import annotationsimport os+import shleximport sysfrom pathlib import Path@@ -47,8 +48,12 @@ def render_ytdlp_fix_command() -> str:" Add-Content -Path $cfg -Value '--js-runtimes node'\n""}")+ config_dir = shlex.quote(str(config_path.parent))+ config_file = shlex.quote(str(config_path))return (- f"mkdir -p '{config_path.parent}' && "- f"grep -qxF -- '--js-runtimes node' '{config_path}' 2>/dev/null || "- f"printf '%s\n' '--js-runtimes node' >> '{config_path}'"+ f"mkdir -p {config_dir} && "+ "{ "+ f"grep -qxF -- '--js-runtimes node' {config_file} 2>/dev/null || "+ f"printf '%s\\n' '--js-runtimes node' >> {config_file}; "+ "}")diff --git a/constraints.txt b/constraints.txtindex f4be507d..20fb6d39 100644--- a/constraints.txt+++ b/constraints.txt@@ -8,7 +8,8 @@ python-dotenv==1.2.1loguru==0.7.3PyYAML==6.0.3rich==14.3.2-yt-dlp==2025.5.22+yt-dlp==2026.07.04+yt-dlp-ejs==0.8.0pytest==8.0.0ruff==0.15.1diff --git a/pyproject.toml b/pyproject.tomlindex 12c769a3..919f2a19 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -34,7 +34,7 @@ dependencies = ["loguru>=0.7","pyyaml>=6.0","rich>=13.0",- "yt-dlp>=2024.0",+ "yt-dlp[default]>=2026.07.04",][project.optional-dependencies]diff --git a/tests/test_paths.py b/tests/test_paths.pynew file mode 100644index 00000000..95f83af3--- /dev/null+++ b/tests/test_paths.py@@ -0,0 +1,22 @@+# -*- coding: utf-8 -*-+"""Behavior tests for cross-platform path and remediation helpers."""++import subprocess++from agent_reach.utils import paths+++def test_posix_ytdlp_fix_is_single_line_executable_and_idempotent(+ monkeypatch, tmp_path+):+ monkeypatch.setattr(paths.sys, "platform", "linux")+ monkeypatch.setattr(paths.Path, "home", classmethod(lambda cls: tmp_path))++ command = paths.render_ytdlp_fix_command()++ assert "\n" not in command+ subprocess.run(["/bin/sh", "-c", command], check=True)+ subprocess.run(["/bin/sh", "-c", command], check=True)++ config = tmp_path / ".config" / "yt-dlp" / "config"+ assert config.read_text(encoding="utf-8") == "--js-runtimes node\n"diff --git a/tests/test_youtube_channel.py b/tests/test_youtube_channel.pyindex 73c6edf7..923ae5eb 100644--- a/tests/test_youtube_channel.py+++ b/tests/test_youtube_channel.py@@ -11,11 +11,12 @@ channel coverage after rss (#360), github (#361), web (#363),reddit (#364), xueqiu (#365) and v2ex (#366)."""+from pathlib import Pathfrom unittest.mock import Mock, patch-from agent_reach.probe import ProbeResultfrom agent_reach.channels import youtube as ytfrom agent_reach.channels.youtube import YouTubeChannel, _has_js_runtime_config+from agent_reach.probe import ProbeResultdef _which(*present):@@ -112,6 +113,68 @@ def test_check_warn_when_node_only_and_config_missing_flag():assert ch.active_backend == "yt-dlp"+def test_check_tells_user_to_upgrade_when_ytdlp_predates_js_runtimes():+ ch = YouTubeChannel()+ probe = ProbeResult("ok", output="2025.10.22")+ with patch.object(yt, "probe_command", return_value=probe), \+ patch("shutil.which", side_effect=_which("node")), \+ patch.object(yt, "_has_js_runtime_config", return_value=False):+ status, message = ch.check()++ assert status == "warn"+ assert "升级" in message+ assert "--js-runtimes" not in message+ assert ch.active_backend == "yt-dlp"+++def test_check_does_not_prescribe_unverified_flag_when_version_is_unknown():+ ch = YouTubeChannel()+ probe = ProbeResult("ok", output="dev-build")+ with patch.object(yt, "probe_command", return_value=probe), \+ patch("shutil.which", side_effect=_which("node")), \+ patch.object(yt, "_has_js_runtime_config", return_value=False):+ status, message = ch.check()++ assert status == "warn"+ assert "无法确认" in message+ assert "升级" in message+ assert "--js-runtimes" not in message+ assert ch.active_backend == "yt-dlp"+++def test_check_prescribes_js_runtimes_from_first_supported_stable_release():+ ch = YouTubeChannel()+ probe = ProbeResult("ok", output="2025.11.12")+ with patch.object(yt, "probe_command", return_value=probe), \+ patch("shutil.which", side_effect=_which("node")), \+ patch.object(yt, "_has_js_runtime_config", return_value=False):+ status, message = ch.check()++ assert status == "warn"+ assert "--js-runtimes node" in message+ assert ch.active_backend == "yt-dlp"+++def test_constraints_pin_ytdlp_to_current_stable_release():+ constraints = Path(__file__).parents[1] / "constraints.txt"+ pin = next(+ line+ for line in constraints.read_text(encoding="utf-8").splitlines()+ if line.startswith("yt-dlp==")+ )++ assert pin == "yt-dlp==2026.07.04"+++def test_project_installs_official_ytdlp_default_dependencies():+ root = Path(__file__).parents[1]+ pyproject = (root / "pyproject.toml").read_text(encoding="utf-8")+ constraints = (root / "constraints.txt").read_text(encoding="utf-8")++ assert '"yt-dlp[default]>=2026.07.04"' in pyproject+ assert "yt-dlp-ejs==0.8.0" in constraints++def test_check_ok_with_deno():ch = YouTubeChannel()with patch.object(yt, "probe_command", return_value=ProbeResult("ok")), \