关于 yt-dlp-mcp
yt-dlp-mcp 是基于 yt-dlp 的 MCP 服务,让 AI 助手可以通过自然语言获取视频与音频内容。适合需要搜索、查看元数据、获取字幕或下载媒体的用户。
主要功能
- 01YouTube 搜索与分页
- 02视频元数据提取,无需下载内容
- 03VTT 字幕与纯文本转录
- 04视频下载,支持分辨率与裁剪
- 05仅音频下载(M4A/MP3)
- 06评论提取,支持线程视图与 Markdown 输出
适用场景
- 01让 AI 助手总结视频的标题、频道与发布日期
- 02获取指定语言的字幕并生成纯文本转录
- 03按时间段下载视频片段或音频
MCP 相关
该项目是 MCP 服务,向 Claude Code、Claude Desktop、Cursor 等 MCP 客户端提供以 ytdlp_ 为前缀的工具。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
🎬 yt-dlp-mcp
为 AI Agent 提供视频平台功能的强大 MCP 服务
将 yt-dlp 集成到 Claude、Dive 和其他兼容 MCP 的 AI 系统中。通过自然语言下载视频、提取元数据、获取字幕等。
✨ 功能
🔍 搜索与发现
📊 元数据提取
📝 字幕与字幕文件
|
🎥 视频下载
🎵 音频提取
🛡️ 隐私与安全
|
🚀 安装
前置条件
在系统上安装 yt-dlp:
| 平台 | 命令 |
|---|---|
| 🪟 Windows | winget install yt-dlp |
| 🍎 macOS | brew install yt-dlp |
| 🐧 Linux | pip install yt-dlp |
开始使用
将以下配置添加到 MCP 客户端:
{
"mcpServers": {
"yt-dlp": {
"command": "npx",
"args": ["-y", "@kevinwatt/yt-dlp-mcp@latest"]
}
}
}
MCP 客户端配置
Dive
- 打开 Dive 桌面应用
- 点击 "+ Add MCP Server"
- 粘贴上方提供的配置
- 点击 "Save",即可开始使用!
Claude Code
使用 Claude Code CLI 添加 yt-dlp MCP 服务(指南):
claude mcp add yt-dlp npx @kevinwatt/yt-dlp-mcp@latest
Claude Desktop
添加到你的 claude_desktop_config.json:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
{
"mcpServers": {
"yt-dlp": {
"command": "npx",
"args": ["-y", "@kevinwatt/yt-dlp-mcp@latest"]
}
}
}
Cursor
前往 Cursor Settings -> MCP -> New MCP Server。使用上方提供的配置。
VS Code / Copilot
通过 VS Code CLI 安装:
code --add-mcp '{"name":"yt-dlp","command":"npx","args":["-y","@kevinwatt/yt-dlp-mcp@latest"]}'
或者按照 MCP 安装指南,使用上方的标准配置。
Windsurf
按照配置 MCP 指南,使用上方的标准配置。
Cline
按照 Cline MCP 配置指南,使用上方提供的配置。
Warp
前往 Settings | AI | Manage MCP Servers -> + Add,以添加 MCP 服务。使用上方提供的配置。
JetBrains AI Assistant
前往 Settings | Tools | AI Assistant | Model Context Protocol (MCP) -> Add。使用上方提供的配置。
手动安装
npm install -g @kevinwatt/yt-dlp-mcp
🛠️ 可用工具
所有工具均以 ytdlp_ 为前缀,以避免与其他 MCP 服务发生命名冲突。
🔍 搜索与发现
| 工具 | 说明 |
|---|---|
ytdlp_search_videos |
搜索 YouTube,支持分页和日期筛选
|
📝 字幕与文字稿
| 工具 | 说明 |
|---|---|
ytdlp_list_subtitle_languages |
列出视频所有可用的字幕语言
|
ytdlp_download_video_subtitles |
下载带时间戳的 VTT 格式字幕
|
ytdlp_download_transcript |
生成整洁的纯文本文字稿
|
🎥 视频与音频下载
| 工具 | 说明 |
|---|---|
ytdlp_download_video |
将视频下载到 Downloads 文件夹
|
ytdlp_download_audio |
仅提取并下载音频
|
| 工具 | 描述 |
|---|---|
ytdlp_get_video_metadata |
以 JSON 格式提取全面的视频元数据
|
ytdlp_get_video_metadata_summary |
获取易于阅读的元数据摘要
|
💬 评论
| 工具 | 描述 |
|---|---|
ytdlp_get_video_comments |
以扁平 JSON、线程化 JSON 或适合 AI 的 Markdown 格式提取评论
|
ytdlp_get_video_comments_summary |
获取易于阅读的评论摘要
|
💡 使用示例
搜索视频
"Search for Python programming tutorials"
"Find the top 20 machine learning videos"
"Search for 'react hooks tutorial' and show results 10-20"
"Search for JavaScript courses in JSON format"
获取元数据
"Get metadata for https://youtube.com/watch?v=..."
"Show me the title, channel, and view count for this video"
"Extract just the duration and upload date"
"Give me a quick summary of this video's info"
获取评论
"Get the top 20 comments for https://youtube.com/watch?v=..."
"Get comments as threaded JSON for this video"
"Extract comments as markdown_tree so the reply branches stay intact"
"Get newest comments with maxDepth 1 and maxRepliesPerThread 0"
"Summarize comments in threaded view"
下载字幕和转录文本
"List available subtitles for https://youtube.com/watch?v=..."
"Download English subtitles from this video"
"Get a clean transcript of this video in Spanish"
"Download Chinese (zh-Hant) transcript"
下载内容
"Download this video in 1080p: https://youtube.com/watch?v=..."
"Download audio from this YouTube video"
"Download this video from 1:30 to 2:45"
"Save this Facebook video to my Downloads"
📖 文档
🔧 配置
环境变量
# Downloads directory (default: ~/Downloads)
YTDLP_DOWNLOADS_DIR=/path/to/downloads
# Default resolution (default: 720p)
YTDLP_DEFAULT_RESOLUTION=1080p
# Default subtitle language (default: en)
YTDLP_DEFAULT_SUBTITLE_LANG=en
完整列表请参阅配置指南。
代理和 yt-dlp 配置文件
所有工具都会读取你的 yt-dlp 配置文件(~/.config/yt-dlp/config),因此其中设置的任何
--proxy、--cookies 或其他选项都会自动生效。对于无法向服务进程传递环境变量的 MCP 客户端来说,这是唯一可用的方式。
以下选项互为替代——只设置你需要的选项:
| 设置 | 效果 |
|---|---|
YTDLP_PROXY=socks5://127.0.0.1:1080 | 通过此代理路由所有请求 |
YTDLP_PROXY=(空) | 强制直接连接,覆盖 yt-dlp 配置文件中的代理设置 |
YTDLP_IGNORE_CONFIG=1 | 跳过所有 yt-dlp 配置文件 |
支持的代理协议:http、https、socks4、socks5、socks5h。
YTDLP_IGNORE_CONFIG=1并不等同于直接回退到 0.9.x。搜索、元数据和评论工具始终会读取配置文件,因此此设置也会阻止它们读取配置文件。
使用代理的 MCP 配置:
{
"mcpServers": {
"yt-dlp": {
"command": "npx",
"args": ["-y", "@kevinwatt/yt-dlp-mcp@latest"],
"env": {
"YTDLP_PROXY": "socks5://127.0.0.1:1080"
}
}
}
}
如果你的 MCP 客户端无法向服务传递环境变量,请改为将选项写入 ~/.config/yt-dlp/config——每个工具都会读取该文件:
--proxy socks5://127.0.0.1:1080
--cookies /path/to/cookies.txt
注意:你的配置文件也会应用于下载。更改输出格式的选项(
-x、--remux-video、--recode-video)会改变下载工具生成的内容;工具会报告 yt-dlp 实际写入的文件,因此报告的名称仍然准确。输出位置选项(-o、-P)不会生效,因为工具始终会在命令行中传入绝对路径的--output,而它的优先级更高。注意:yt-dlp 配置文件可以包含用于执行命令的选项(
--exec、--postprocessor-args、--ffmpeg-location)。现在,这些选项也会在调用工具时运行,包括由 AI 助手触发的调用。如果你希望服务完全忽略配置文件,请设置YTDLP_IGNORE_CONFIG=1。
Cookie 配置
要访问私人视频、年龄限制内容或避免触发速率限制,请配置 Cookie:
⚠️ 重要:Cookie 身份验证要求安装 JavaScript 运行时(deno)。使用 Cookie 时,YouTube 会使用需要 JavaScript 挑战求解的已验证 API 端点。如果没有 deno,下载会失败并报错:"n challenge solving failed"。
安装 deno:https://docs.deno.com/runtime/getting_started/installation/
# Extract cookies from browser (recommended)
YTDLP_COOKIES_FROM_BROWSER=chrome
# Or use a cookie file
YTDLP_COOKIES_FILE=/path/to/cookies.txt
使用 Cookie 的 MCP 配置:
{
"mcpServers": {
"yt-dlp": {
"command": "npx",
"args": ["-y", "@kevinwatt/yt-dlp-mcp@latest"],
"env": {
"YTDLP_COOKIES_FROM_BROWSER": "chrome"
}
}
}
}
支持的浏览器:brave、chrome、chromium、edge、firefox、opera、safari、vivaldi、whale
详细设置说明请参阅 Cookie 配置指南。
🏗️ 架构
构建所用技术
主要功能
- ✅ 类型安全:全面使用 TypeScript 并启用严格模式
- ✅ 输入验证:使用 Zod 模式进行运行时验证
- ✅ 字符数限制:自动截断,防止上下文溢出
- ✅ 工具注解:readOnly、destructive、idempotent 提示
- ✅ 错误指引:为 LLM 提供可操作的错误消息
- ✅ 模块化设计:清晰划分关注点
📊 响应格式
JSON 格式
适合以编程方式处理:
{
"total": 50,
"count": 10,
"offset": 0,
"videos": [...],
"has_more": true,
"next_offset": 10
}
Markdown 格式
便于人类阅读:
Found 50 videos (showing 10):
1. **Video Title**
📺 Channel: Creator Name
⏱️ Duration: 10:30
🔗 URL: https://...
评论 Markdown 树
回复上下文很重要时,适用于 LLM 分析:
# AI-Ready Comment Threads
source_title: "Sample Video"
comments_detected: 20
root_threads: 6
reply_comments: 14
## Threads
### Thread 1
- comment_id: "abc123"
parent_id: "root"
depth: 0
reply_count: 2
text:
| Root comment text
- comment_id: "reply456"
parent_id: "abc123"
depth: 1
reply_count: 0
text:
| Reply text
评论限制
YouTube 评论提取支持完整的提取器元组:
youtube:comment_sort=<sort>;max_comments=<total>,<parents>,<replies>,<repliesPerThread>,<depth>
示例:
- 默认行为:
maxComments=20会生成max_comments=20,20,20,20,2 - 仅提取根评论:
maxDepth=1、maxRepliesPerThread=0 - 限制分支:
maxReplies=40、maxRepliesPerThread=5、maxDepth=2
🔒 隐私与安全
- 无跟踪:直接下载,不进行分析
- 输入验证:Zod 模式可防止注入
- URL 验证:严格检查 URL 格式
- 字符限制:防止上下文溢出攻击
- 默认只读:大多数工具不会修改系统状态
🤝 参与贡献
欢迎贡献!请查看我们的贡献指南。
- Fork 仓库
- 创建功能分支(
git checkout -b feature/amazing-feature) - 提交更改(
git commit -m 'Add amazing feature') - 推送到分支(
git push origin feature/amazing-feature) - 发起 Pull Request
📝 许可证
本项目采用 MIT 许可证授权,详情请参阅 LICENSE 文件。
🙏 致谢
📚 相关项目
- MCP Servers - 官方 MCP 服务实现
- yt-dlp - 命令行视频下载器
- Dive Desktop - AI Agent 平台
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。