Skip to main content
Glama

yt

面向智能体的 YouTube CLI —— 提供搜索、字幕、元数据以及用于 AI 上下文检索的本地 FTS5 缓存。通过 JSON 信封、NDJSON 流和 MCP 二进制文件封装了 yt-dlp。

无需 YouTube Data API 密钥。无配额限制。默认路径下无速率限制上限。

██╗   ██╗████████╗
╚██╗ ██╔╝╚══██╔══╝
 ╚████╔╝    ██║
  ╚██╔╝     ██║
   ██║      ██║
   ╚═╝      ╚═╝

为什么选择它

现有的 YouTube 工具要么:

  • 为人类构建(如 ytfzf 等交互式 TUI),

  • 为内容创作者构建(利基分析、竞争对手审计),

  • 或者锁定在仅限 MCP 的服务器中。

yt 是为智能体构建的 —— 适用于 Claude Code、Cursor、Codex、Gemini CLI 和你的 bash 脚本。只需一次调用 (yt context <url>),即可将 LLM 推理视频所需的一切信息交给它。

安装

# Requires yt-dlp on PATH
brew install yt-dlp

# From source
git clone https://github.com/progrmoiz/yt-cli
cd yt-cli
npm install && npm run build && npm link

完整性检查:

yt doctor

快速开始

# Search
yt search "rust async" --limit 5

# Grok a single video (the 80% agent use case)
yt context https://www.youtube.com/watch?v=dQw4w9WgXcQ

# Fetch transcript
yt transcript https://www.youtube.com/watch?v=dQw4w9WgXcQ --text

# Query everything you've cached
yt find "borrow checker"

# List a channel's recent videos
yt channel @ThePrimeTimeagen --limit 20

管道传输会自动将输出切换为 JSON(redis-cli 模式):

yt search "typescript" | jq '.data[0].url'
yt context <url> | jq '.data.transcript.full_text'

命令

命令

描述

yt search <query>

YouTube 搜索,无需 API 密钥。支持 --limit、--since 7d。

yt transcript <url>

带时间戳的 JSON 字幕。已缓存。支持 --lang en、--text。

yt info <url>

元数据:标题、频道、章节、时长。已缓存。

yt context <url>

核心功能。 为智能体提供一次性信息 + 字幕 + 章节。

yt find <query>

对缓存的字幕进行 FTS5 搜索。返回带时间戳的行级匹配结果。

yt channel <handle|id|url>

频道的最新视频。

yt doctor [--deep]

诊断:yt-dlp、缓存、智能体检测。

yt self-test

回归测试套件 —— 用于捕获 YouTube 端点失效。

yt schema <cmd>

该命令输出的 JSON 模式。

yt mcp serve

Stdio MCP 服务器。二进制文件。

智能体集成

Claude Code / Cursor / 等 —— MCP

// .mcp.json
{
  "mcpServers": {
    "yt": { "command": "yt", "args": ["mcp", "serve"] }
  }
}

工具与 CLI 命令一一对应:search、info、transcript、context、find、channel、whoami。

脚本 / shell

# Ingest the top 10 search hits into the local cache
yt search "machine learning ops" --limit 10 --json \
  | jq -r '.data[].url' \
  | xargs -I{} yt transcript {} --json >/dev/null

# Then query across all of them
yt find "feature store" --limit 5

缓存

SQLite 数据库位于 ~/.cache/yt/yt.db。内容包括:

  • videos — 每个视频一行(元数据)。

  • transcripts — 每对(视频,语言)一行。

  • transcript_segments_fts — 针对每个字幕片段的 FTS5 虚拟表。

可通过 YT_CACHE_DIR=/path/to/dir 进行覆盖。

每次 transcript / info / context 调用都会先检查缓存。传入 --refresh 可强制重新获取。

输出格式

默认信封 (v2):

{
  "version": "2",
  "status": "success",
  "command": "context",
  "cli": { "name": "yt", "version": "0.1.0" },
  "data": { /* command payload */ },
  "metadata": {
    "elapsed_ms": 1200,
    "cached": true,
    "has_transcript": true,
    "agent": "CLAUDECODE"
  }
}

使用 --raw 获取原始数据。通过 yt schema <command> 获取完整 JSON 模式。

退出代码

0 成功 · 1 通用错误 · 2 用法错误 · 3 验证错误 · 4 认证错误 · 5 速率限制 · 6 网络错误 · 7 未找到 · 75 临时失败

环境变量

变量

用途

YT_CACHE_DIR

缓存目录(默认:~/.cache/yt)

YT_DLP_BIN

覆盖 yt-dlp 二进制文件的路径

YT_NO_RETRY

设置为 1 以禁用 RATE_LIMIT/NETWORK/TIMEOUT 时的单次自动重试

YT_JSON=1

强制 JSON 输出

YT_API_KEY

为未来的 Data API 扩展预留

NO_COLOR

禁用 ANSI 颜色

CI

强制非交互模式

许可证

MIT。

Related MCP Connectors

  • YouTube transcripts, search, channel browsing, and playlists for AI agents via MCP.

  • An MCP server that gives any LLM or agent clean YouTube transcripts on demand: a single video, a whole channel, or a playlist, plus AI cleanup of auto-generated captions. API-key auth, credit-based, same backend as the public v1 API. Get a free API key with 25 free credits at youtubetranscriptdownload.com/account.

  • YouTube transcripts, search, channel/playlist listings and upload tracking for AI agents.

  • Your agent needs to find video — which channels own a topic, which videos rank for a phrase, what exists in a given country and language. **What you can ask for** • "Which videos rank for 'rag pipeline tutorial' in the US this month?" • "Find channels publishing about MCP, sorted by relevance." • "What playlists cover this subject in Japanese?" • "Search videos uploaded this week only." **How to use it** Point any MCP client at https://mcp.aisa.one/youtube-search/mcp and sign in with OAuth — there is no key to create or paste. One search tool covering videos, channels and playlists, narrowed by country, language, upload date, duration and sort order. **It is also a door to the rest** The same login reaches 26 sources and 580+ operations. Find the video here, then ask the same agent what the channel's site traffic is or what the same phrase does in Google — without adding a second server. **What it costs** Finding and inspecting an operation is free. Running one is billed per call at API prices, with no seat and no monthly minimum, and every call takes max_price_usd so an agent cannot overspend by accident. **Where else it reaches** https://mcp.aisa.one/social/mcp for X plus Instagram, Reddit, Pinterest and YouTube; https://mcp.aisa.one/gtm/mcp for those plus Similarweb and Apollo.