介绍
# YouTube Playlist
浏览播放列表并通过 [TranscriptAPI.com](https://transcriptapi.com) 获取字幕。
## 设置
如果未设置 `$TRANSCRIPT_API_KEY`,请帮助用户创建账户(100 个免费额度,无需信用卡):
**第 1 步 — 注册:** 询问用户的电子邮件。
```bash node ./scripts/tapi-auth.js register --email USER_EMAIL ```
→ OTP 已发送至电子邮件。询问用户:_“请检查您的电子邮件以获取 6 位数字验证码。”_
**第 2 步 — 验证:** 用户提供 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。
## 文件写入
verify 和 save-key 命令会将 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) — 请查阅此内容以获取最新参数和架构。
## GET /api/v2/youtube/playlist/videos — 1 积分/页
分页播放列表视频列表(每页 100 个)。接受 `playlist` — YouTube 播放列表 URL 或播放列表 ID。
```bash # First page curl -s "https://transcriptapi.com/api/v2/youtube/playlist/videos?playlist=PL_PLAYLIST_ID" \ -H "Authorization: Bearer $TRANSCRIPT_API_KEY"
# Next pages curl -s "https://transcriptapi.com/api/v2/youtube/playlist/videos?continuation=TOKEN" \ -H "Authorization: Bearer $TRANSCRIPT_API_KEY" ```
| 参数 | 是否必填 | 验证规则 | | -------------- | ----------- | ---------------------------------------------------- | | `playlist` | 条件必填 | 播放列表 URL 或 ID(`PL`/`UU`/`LL`/`FL`/`OL` 前缀) | | `continuation` | 条件必填 | 非空字符串 |
请提供 `playlist` 或 `continuation` 中的 exactly 一个,不要同时提供。
**接受的播放列表 ID 前缀:**
- `PL` — 用户创建的播放列表 - `UU` — 频道上传视频播放列表 - `LL` — 喜欢的视频 - `FL` — 收藏夹 - `OL` — 其他系统播放列表
**响应:**
```json { "results": [ { "videoId": "abc123xyz00", "title": "Playlist Video Title", "channelId": "UCuAXFkgsw1L7xaCfnd5JJOw", "channelTitle": "Channel Name", "channelHandle": "@handle", "lengthText": "10:05", "viewCountText": "1.5M views", "thumbnails": [{ "url": "...", "width": 120, "height": 90 }], "index": "0" } ], "playlist_info": { "title": "Best Science Talks", "numVideos": "47", "description": "Top science presentations", "ownerName": "TED", "viewCount": "5000000" }, "continuation_token": "4qmFsgKlARIYVVV1...", "has_more": true } ```
**分页流程:**
1. 第一次请求:`?playlist=PLxxx` — 返回前 100 个视频 + `continuation_token` 2. 下一次请求:`?continuation=TOKEN` — 返回接下来的 100 个视频 + 新 token 3. 重复直到 `has_more: false` 或 `continuation_token: null`
## 工作流:播放列表 → 字幕
```bash # 1. List playlist videos curl -s "https://transcriptapi.com/api/v2/youtube/playlist/videos?playlist=PL_PLAYLIST_ID" \ -H "Authorization: Bearer $TRANSCRIPT_API_KEY"
# 2. Get transcript from a video in the playlist curl -s "https://transcriptapi.com/api/v2/youtube/transcript\ ?video_url=VIDEO_ID&format=text&include_timestamp=true&send_metadata=true" \ -H "Authorization: Bearer $TRANSCRIPT_API_KEY" ```
## 从 URL 中提取播放列表 ID
对于 `https://www.youtube.com/playlist?list=PLrAXtmErZgOeiKm4sgNOknGvNjby9efdf`,播放列表 ID 为 `PLrAXtmErZgOeiKm4sgNOknGvNjby9efdf`。您也可以直接将完整 URL 传递给 `playlist` 参数。
## 错误
| 代码 | 含义 | 操作 | | ---- | -------------------------- | ------------------------------------------------ | | 400 | 参数两者都有或都没有 | 请仅提供 playlist 或 continuation 中的一个 | | 402 | 没有积分 | transcriptapi.com/billing | | 404 | 未找到播放列表 | 检查播放列表是否公开 | | 408 | 超时 | 重试一次 | | 422 | 播放列表格式无效 | 必须是有效的播放列表 URL 或 ID |
每页 1 个积分。免费套餐:100 个积分,300 请求/分钟。