fix: YouTube requires JS runtime — auto-configure Node.js in install
yt-dlp now requires an external JS runtime (deno or Node.js) for YouTube. Since agent-reach already installs Node.js, we configure yt-dlp to use it: 1. cli.py: install writes '--js-runtimes node' to ~/.config/yt-dlp/config 2. youtube.py: doctor checks JS runtime availability and config 3. SKILL.md: updated YouTube section with accurate troubleshooting Bilibili note: 412 errors are IP-based (needs proxy), not cookie-related. Fixes #47
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""YouTube — check if yt-dlp is available."""
|
||||
"""YouTube — check if yt-dlp is available with JS runtime."""
|
||||
|
||||
import os
|
||||
import shutil
|
||||
from .base import Channel
|
||||
|
||||
@@ -17,6 +18,23 @@ class YouTubeChannel(Channel):
|
||||
return "youtube.com" in d or "youtu.be" in d
|
||||
|
||||
def check(self, config=None):
|
||||
if shutil.which("yt-dlp"):
|
||||
return "ok", "可提取视频信息和字幕"
|
||||
return "off", "yt-dlp 未安装。安装:pip install yt-dlp"
|
||||
if not shutil.which("yt-dlp"):
|
||||
return "off", "yt-dlp 未安装。安装:pip install yt-dlp"
|
||||
# Check JS runtime
|
||||
has_js = shutil.which("deno") or shutil.which("node")
|
||||
if not has_js:
|
||||
return "warn", (
|
||||
"yt-dlp 已安装但缺少 JS runtime(YouTube 必须)。\n"
|
||||
" 安装 Node.js 或 deno,然后运行:agent-reach install"
|
||||
)
|
||||
# Check yt-dlp config for --js-runtimes
|
||||
ytdlp_config = os.path.expanduser("~/.config/yt-dlp/config")
|
||||
has_deno = shutil.which("deno")
|
||||
if not has_deno and os.path.exists(ytdlp_config):
|
||||
with open(ytdlp_config, "r") as f:
|
||||
if "--js-runtimes" not in f.read():
|
||||
return "warn", (
|
||||
"yt-dlp 已安装但未配置 JS runtime。运行:\n"
|
||||
" mkdir -p ~/.config/yt-dlp && echo '--js-runtimes node' >> ~/.config/yt-dlp/config"
|
||||
)
|
||||
return "ok", "可提取视频信息和字幕"
|
||||
|
||||
Reference in New Issue
Block a user