关于 youtube-data
youtube-data 是通过 TranscriptAPI.com 获取 YouTube 数据的技能,面向需要视频、频道和播放列表信息的 Agent。它涵盖字幕稿、元数据、搜索及频道内容等接口。
主要功能
- 01获取字幕稿和视频元数据
- 02搜索视频、频道和播放列表
- 03查询频道视频、动态和资料
- 04列出播放列表视频
- 05分页获取频道与播放列表内容
适用场景
- 01查找特定主题的视频
- 02分析频道发布内容和统计信息
- 03查看视频字幕及丰富元数据
- 04检索频道动态或播放列表
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ zeropointrepo/ youtube-skills --skill youtube-data安装后在 Claude Code 中输入/youtube-data确认已加载。
附带文件references/auth-setup.mdreferences/curl-examples.md
详细介绍
YouTube 数据
通过 TranscriptAPI.com 访问 YouTube 数据——Google YouTube Data API 的轻量级替代方案。
设置
如果未设置 $TRANSCRIPT_API_KEY,请阅读 references/auth-setup.md,并按照其中的说明获取和保存密钥。
必需的请求头
每个请求都需要两个请求头:
- Authorization:
Bearer $TRANSCRIPT_API_KEY - User-Agent: 已知时填写 Agent 的名称和版本(例如
HermesAgent/0.11.0、ClaudeCode/1.0)。版本可选,只填写 Agent 名称也可以。请勿省略此请求头,也不要发送默认值——否则 Cloudflare 会返回 403(错误代码 1010)并阻止请求。
API 参考
完整的 OpenAPI 规范:transcriptapi.com/openapi.json——请参阅此规范,了解最新参数和架构。
视频数据(字幕稿 + 元数据)——1 个积分
GET https://transcriptapi.com/api/v2/youtube/transcript?video_url=VIDEO_URL&format=json&include_timestamp=true&send_metadata=true
Authorization: Bearer $TRANSCRIPT_API_KEY
User-Agent: YourAgent/1.0
响应:
{
"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 个积分):
GET https://transcriptapi.com/api/v2/youtube/info?video_url=VIDEO_URL
Authorization: Bearer $TRANSCRIPT_API_KEY
User-Agent: YourAgent/1.0
GET https://transcriptapi.com/api/v2/youtube/video/metadata?video_url=VIDEO_URL&include=details,related
Authorization: Bearer $TRANSCRIPT_API_KEY
User-Agent: YourAgent/1.0
video/metadata 会返回 title、viewCountText、likeCountText、publishDate、description、descriptionLinks、channel、thumbnails,以及 details(时长、类别、标签、字幕轨道);通过 include 请求时,还会返回相关的 related 视频。
命名:
/video/metadata之前的路径是/video/info。旧路径仍可使用,但已弃用。
搜索数据——每页 1 个积分
GET https://transcriptapi.com/api/v2/youtube/search?q=QUERY&type=video&limit=20
Authorization: Bearer $TRANSCRIPT_API_KEY
User-Agent: YourAgent/1.0
type 也接受 playlist 和 movie。仅限第一页;你可以添加 sort(relevance/views)、upload_date(hour/today/week/month/year)、duration(short/medium/long)和 features(例如 hd,subtitles,cc)。
视频结果字段: 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(免费):
GET https://transcriptapi.com/api/v2/youtube/channel/resolve?input=@TED
Authorization: Bearer $TRANSCRIPT_API_KEY
User-Agent: YourAgent/1.0
返回:{"channel_id": "UCsT0YIqwnpJCM-mx7-gSA4Q", "resolved_from": "@TED"}
最新的 15 个视频及精确统计数据(免费):
GET https://transcriptapi.com/api/v2/youtube/channel/latest?channel=@TED
Authorization: Bearer $TRANSCRIPT_API_KEY
User-Agent: YourAgent/1.0
返回:channel 信息,以及包含 videoId、title、published(ISO 格式)、viewCount(精确数值)、description、thumbnail 的 results 数组
频道的所有视频(分页,每页 1 个 credit):
GET https://transcriptapi.com/api/v2/youtube/channel/videos?channel=@NASA&tab=videos
Authorization: Bearer $TRANSCRIPT_API_KEY
User-Agent: YourAgent/1.0
# Most-viewed first (channel Videos tab, ~30 per page)
GET https://transcriptapi.com/api/v2/youtube/channel/videos?channel=@NASA&sort=popular
Authorization: Bearer $TRANSCRIPT_API_KEY
User-Agent: YourAgent/1.0
每页返回约 100 个视频,以及用于分页的 continuation_token。tab 也接受 shorts 或 streams,分页时需重复使用相同的 tab。
排序。 将 sort=latest、popular 或 oldest 添加到 channel/videos,即可按所需顺序获取频道视频,例如优先显示最受欢迎的上传内容。排序后的页面约返回 30 个视频(未排序的页面约返回 100 个),每页费用相同,均为 1 个 credit。
分页时,每次请求都发送相同的 sort 值。
条目字段。 每个条目都包含 members_only,仅当 YouTube 将其标记为“Members only”时才为 true,且此类条目没有 viewCountText。tab=streams 条目包含 lengthText 和 publishedTimeText(例如 Streamed 2 years ago);tab=shorts 的这两个字段均为 null,因为 YouTube 的 Shorts 网格不会提供这两项内容。在频道标签页信息流中(带有 sort 的 tab=videos、tab=shorts、tab=streams),channelId、channelTitle、channelHandle 和 index 均为 null。
在频道内搜索(1 个 credit):
GET https://transcriptapi.com/api/v2/youtube/channel/search?channel=@TED&q=QUERY&limit=30
Authorization: Bearer $TRANSCRIPT_API_KEY
User-Agent: YourAgent/1.0
频道资料(1 个 credit):
GET https://transcriptapi.com/api/v2/youtube/channel/info?channel=@TED
Authorization: Bearer $TRANSCRIPT_API_KEY
User-Agent: YourAgent/1.0
返回:title、handle、verified、subscriberCountText、videoCountText、description、tags、thumbnails、banners、availableTabs
频道播放列表(每页 1 个 credit):
GET https://transcriptapi.com/api/v2/youtube/channel/playlists?channel=@TED
Authorization: Bearer $TRANSCRIPT_API_KEY
User-Agent: YourAgent/1.0
返回:results(playlistId、title、url、videoCountText、thumbnails)、continuation_token、has_more
频道社区帖子(每页 1 个 credit):
GET https://transcriptapi.com/api/v2/youtube/channel/posts?channel=@TED
Authorization: Bearer $TRANSCRIPT_API_KEY
User-Agent: YourAgent/1.0
返回:results(postId、authorName、text、publishedTimeText、voteCountText、attachment)、continuation_token、has_more
频道精选版块(1 个 credit):
GET https://transcriptapi.com/api/v2/youtube/channel/sections?channel=@TED
Authorization: Bearer $TRANSCRIPT_API_KEY
User-Agent: YourAgent/1.0
按频道自身的顺序返回视频、播放列表、Shorts 和精选频道的内容架。tab 也接受 podcasts 或 releases。
播放列表数据 — 每页 1 个 credit
接受 playlist——YouTube 播放列表 URL 或播放列表 ID。
GET https://transcriptapi.com/api/v2/youtube/playlist/videos?playlist=PL_ID
Authorization: Bearer $TRANSCRIPT_API_KEY
User-Agent: YourAgent/1.0
返回:results(视频)、playlist_info(title、numVideos、ownerName、viewCount)、continuation_token、has_more
Credit 费用
| 端点 | 费用 | 返回的数据 |
|---|---|---|
| transcript | 1 | 完整字幕 + 元数据 |
| info | 免费 | 基本元数据 + 语言 |
| video/metadata | 1 | 丰富的元数据(+ 详细信息/相关内容) |
| search | 1/页 | 视频/频道/播放列表/电影详情 |
| channel/resolve | 免费 | 频道 ID 映射 |
| channel/info | 1 | 频道资料 |
| channel/latest | 免费 | 15 个视频 + 精确统计数据 |
| channel/videos | 1/页 | 未排序时约 100 个/页,排序时约 30 个/页 |
| channel/search | 1 | 符合查询条件的视频 |
| channel/playlists | 1/页 | 频道的播放列表 |
| channel/posts | 1/页 | 社区标签页内容 |
| channel/sections | 1 | 精选的主页内容架 |
| playlist/videos | 1/页 | 每页 100 个视频 |
错误
| 代码 | 含义 | 操作 |
|---|---|---|
| 401 | API 密钥错误 | 检查密钥 |
| 402 | 没有额度 | transcriptapi.com/billing |
| 403/1010 | Cloudflare 拦截 | 添加或修正 User-Agent 请求头 |
| 404 | 未找到 | 资源不存在 |
| 408 | 超时 | 重试一次 |
| 422 | 验证错误 | 检查参数格式 |
免费套餐:100 个额度,每分钟 300 次请求。
复制粘贴示例
此文件中的每个请求都提供了可直接运行的单行命令:references/curl-examples.md