ClawSkills logoClawSkills

Youtube Data

访问 YouTube 视频数据——包括文字记录、元数据、频道信息、搜索和播放列表。作为 Google YouTube Data API 的轻量级替代方案,无配额限制。

介绍

# YouTube Data

通过 [TranscriptAPI.com](https://transcriptapi.com) 访问 YouTube 数据——这是 Google YouTube Data API 的轻量级替代方案。

## 设置

如果未设置 `$TRANSCRIPT_API_KEY`,请协助用户创建账户(100 个免费积分,无需信用卡):

**第一步 — 注册:** 询问用户的电子邮件。

```bash node ./scripts/tapi-auth.js register --email USER_EMAIL ```

→ OTP 已发送至电子邮件。询问用户:_“请检查您的电子邮件以获取 6 位验证码。”_

**第二步 — 验证:** 当用户提供 OTP 后:

```bash node ./scripts/tapi-auth.js verify --token TOKEN_FROM_STEP_1 --otp CODE ```

> API 密钥已保存至 `~/.openclaw/openclaw.json`。详情请参阅下方的 **文件写入**。现有文件在修改前会进行备份。

手动选项:[transcriptapi.com/signup](https://transcriptapi.com/signup) → Dashboard → API Keys。

## 文件写入

验证和保存密钥命令会将 API 密钥保存到 `~/.openclaw/openclaw.json`(设置 `skills.entries.transcriptapi.apiKey` 和 `enabled: true`)。**现有文件在修改前会备份到 `~/.openclaw/openclaw.json.bak`。**

要在代理之外的终端/CLI 中使用 API 密钥,请手动添加到您的 shell 配置文件中: `export TRANSCRIPT_API_KEY=<your-key>`

## API 参考

完整的 OpenAPI 规范:[transcriptapi.com/openapi.json](https://transcriptapi.com/openapi.json) — 请查阅以获取最新的参数和架构。

## 视频数据(字幕 + 元数据)— 1 积分

```bash curl -s "https://transcriptapi.com/api/v2/youtube/transcript\ ?video_url=VIDEO_URL&format=json&include_timestamp=true&send_metadata=true" \ -H "Authorization: Bearer $TRANSCRIPT_API_KEY" ```

**响应:**

```json { "video_id": "dQw4w9WgXcQ", "language": "en", "transcript": [ { "text": "We're no strangers to love", "start": 18.0, "duration": 3.5 } ], "metadata": { "title": "Rick Astley - Never Gonna Give You Up", "author_name": "Rick Astley", "author_url": "https://www.youtube.com/@RickAstley", "thumbnail_url": "https://i.ytimg.com/vi/dQw4w9WgXcQ/maxresdefault.jpg" } } ```

## 搜索数据 — 1 积分

```bash curl -s "https://transcriptapi.com/api/v2/youtube/search?q=QUERY&type=video&limit=20" \ -H "Authorization: Bearer $TRANSCRIPT_API_KEY" ```

**视频结果字段:** `videoId`、`title`、`channelId`、`channelTitle`、`channelHandle`、`channelVerified`、`lengthText`、`viewCountText`、`publishedTimeText`、`hasCaptions`、`thumbnails`

**频道结果字段**(`type=channel`):`channelId`、`title`、`handle`、`url`、`description`、`subscriberCount`、`verified`、`rssUrl`、`thumbnails`

## 频道数据

频道端点接受 `channel` —— 一个 `@handle`、频道 URL 或 `UC...` ID。无需预先解析。

**解析 handle 为 ID(免费):**

```bash curl -s "https://transcriptapi.com/api/v2/youtube/channel/resolve?input=@TED" \ -H "Authorization: Bearer $TRANSCRIPT_API_KEY" ```

返回:`{"channel_id": "UCsT0YIqwnpJCM-mx7-gSA4Q", "resolved_from": "@TED"}`

**最新的 15 个视频及精确统计(免费):**

```bash curl -s "https://transcriptapi.com/api/v2/youtube/channel/latest?channel=@TED" \ -H "Authorization: Bearer $TRANSCRIPT_API_KEY" ```

返回:`channel` 信息、包含 `videoId`、`title`、`published`(ISO 格式)、`viewCount`(精确数字)、`description`、`thumbnail` 的 `results` 数组

**所有频道视频(分页,1 积分/页):**

```bash curl -s "https://transcriptapi.com/api/v2/youtube/channel/videos?channel=@NASA" \ -H "Authorization: Bearer $TRANSCRIPT_API_KEY" ```

每页返回 100 个视频 + 用于分页的 `continuation_token`。

**频道内搜索(1 积分):**

```bash curl -s "https://transcriptapi.com/api/v2/youtube/channel/search\ ?channel=@TED&q=QUERY&limit=30" \ -H "Authorization: Bearer $TRANSCRIPT_API_KEY" ```

## 播放列表数据 — 1 积分/页

接受 `playlist` —— YouTube 播放列表 URL 或播放列表 ID。

```bash curl -s "https://transcriptapi.com/api/v2/youtube/playlist/videos?playlist=PL_ID" \ -H "Authorization: Bearer $TRANSCRIPT_API_KEY" ```

返回:`results`(视频)、`playlist_info`(`title`、`numVideos`、`ownerName`、`viewCount`)、`continuation_token`、`has_more`

## 积分消耗

| 端点 | 消耗 | 返回数据 | | --------------- | ---------- | ------------------------- | | transcript | 1 | 完整字幕 + 元数据 | | search | 1 | 视频/频道详情 | | channel/resolve | **免费** | 频道 ID 映射 | | channel/latest | **免费** | 15 个视频 + 精确统计 | | channel/videos | 1/页 | 每页 100 个视频 | | channel/search | 1 | 与查询匹配的视频 | | playlist/videos | 1/页 | 每页 100 个视频 |

## 错误

| 代码 | 操作 | | ---- | -------------------------------------- | | 402 | 积分不足 — transcriptapi.com/billing | | 404 | 未找到 | | 408 | 超时 — 重试一次 | | 422 | 无效的参数格式 |

免费套餐:100 积分,300 次请求/分钟。

更多产品