youtube-ai

youtube-ai

Provides read-only MCP tools to search YouTube, retrieve video metadata, transcripts, comments, channel information, and popular videos.

Category
访问服务器

README

<div align="center">

<img src="https://github.com/vibheksoni/youtube-ai/raw/main/assets/YTAI.png" alt="YTAI" width="320">

YTAI: Python YouTube SDK, CLI & MCP Server

Search, metadata, transcripts, comments, channels, and downloads — no API key required.

PyPI Python License Stars Downloads

curl_cffi for TLS impersonation · FastMCP for agent tools · FastAPI for HTTP API · Rich for CLI

</div>

YTAI is an independent project. It is not affiliated with or endorsed by YouTube or Google. Use it in accordance with applicable terms, copyright law, and local regulations.

Contents

Features

  • Search videos, channels, and playlists with filters and pagination
  • Retrieve metadata, likes, captions, related videos, and comments
  • Fetch timestamped transcripts with language selection and XML fallback
  • Inspect channels, recent uploads, and popular videos
  • Download full video with audio, video-only, audio-only, or a time range
  • Resume interrupted downloads with ranged transfers and per-chunk retries
  • Cache responses in SQLite with operation-specific TTLs
  • Use the Python SDK, Rich-powered ytai CLI, nine read-only MCP tools, or the FastAPI service

Installation

Requirements:

  • Python 3.10 or newer
  • No separate FFmpeg installation is required for downloads; YTAI bundles FFmpeg through imageio-ffmpeg

Install from PyPI:

pip install youtube-ai

Or clone and install from source:

git clone https://github.com/vibheksoni/youtube-ai.git
cd youtube-ai
pip install -e .

Install development dependencies when running tests:

pip install -e ".[dev]"

FFmpeg is bundled automatically for Windows, macOS, and Linux when you install YTAI. If you prefer a system build, it is used when ffmpeg is on PATH. To pin an explicit binary, set YTAI_FFMPEG_PATH to its full path:

$env:YTAI_FFMPEG_PATH = "C:\tools\ffmpeg\bin\ffmpeg.exe"

YTAI_API_KEY is an optional offline fallback when live configuration cannot be fetched. It is read from the environment and is never stored in the repository.

For environment setup and first-run guidance, continue with Getting Started.

Quick start

Use YouTubeClient as a context manager so its HTTP session is closed cleanly:

from youtube_ai import YouTubeClient

with YouTubeClient() as client:
    results = client.search("python tutorial", limit=5, filter_type="video")
    for item in results["results"]:
        print(item["title"], item["url"])

    video = client.get_video("dQw4w9WgXcQ")
    print(video["details"]["title"])
    print(video["details"]["likes"])

    transcript = client.get_transcript("dQw4w9WgXcQ", language_codes=("en",))
    for segment in transcript["snippets"][:5]:
        print(f"{segment['start']:.1f}s: {segment['text']}")

Common CLI commands:

ytai search "python tutorial" --limit 10 --filter video
ytai video dQw4w9WgXcQ
ytai transcript dQw4w9WgXcQ --lang en
ytai comments dQw4w9WgXcQ --limit 20

See the Python API reference and CLI reference for complete signatures and commands.

Downloads

Inspect available qualities, codecs, stream sizes, and modes before downloading:

ytai download-options dQw4w9WgXcQ

Download a full video with audio:

ytai download dQw4w9WgXcQ --quality 720p --output ./downloads

Video-only, audio-only, and clipping are opt-in:

ytai download dQw4w9WgXcQ --quality 1080p --video-only
ytai download dQw4w9WgXcQ --audio-only
ytai download dQw4w9WgXcQ --quality 360p --start 30 --end 90

The SDK also exposes VideoQuality, DownloadMode, get_download_options(), and download_video(). See the download API and download example.

MCP server

Start the FastMCP server:

python mcp/server.py

It exposes nine read-only tools for search, video data, transcripts, streaming formats, comments, channels, and popular videos. Media downloading is intentionally available through the SDK and CLI only.

See MCP Server Setup for client configuration and tool parameters.

FastAPI server

Start the versioned HTTP API:

ytai-api

Swagger UI is available at http://127.0.0.1:8000/docs. The API covers search, video data, transcripts, comments, formats, download options, channels, and popular videos. See the FastAPI Server Guide for routes, curl examples, configuration, validation, and deployment guidance.

Documentation

  • Getting Started: prerequisites, installation, and first workflows
  • API Reference: public classes, functions, enums, and return shapes
  • CLI Reference: every ytai command and option
  • MCP Server: server setup, tools, parameters, and errors
  • FastAPI Server: HTTP routes, OpenAPI docs, configuration, and examples
  • Examples: runnable search, metadata, transcript, comment, channel, download, and MCP scripts

Testing

The end-to-end suite calls the real YouTube InnerTube and Google Video boundaries. It covers search, transcripts, comments, channels, MCP tools, CLI commands, download modes, clipping, resumable ranges, and ffmpeg output streams.

pytest tests/test_e2e.py -v

Limitations

  • Private, members-only, and most age-restricted content is unavailable without authentication.
  • InnerTube endpoints and renderer structures can change without notice.
  • Channel uploads currently return the first available page.
  • Adaptive full-video downloads and clipping use the bundled FFmpeg executable (or YTAI_FFMPEG_PATH when configured).
  • Playlist contents are not currently fetched.

Credits

YTAI acknowledges these public projects as references for protocol details, format mappings, and implementation ideas:

License

MIT, as declared in pyproject.toml.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选