关于 youtube-apify-transcript
这款命令行技能通过 Apify API 获取 YouTube 视频转录文本,也适用于 YouTube 可能拦截请求的云环境。它在本地缓存结果,并支持文本、带时间戳的 JSON 和批量处理。
主要功能
- 01通过 Apify 获取转录文本
- 02在本地缓存转录结果
- 03输出文本或带时间戳的 JSON
- 04批量处理多个视频 URL
适用场景
- 01获取视频转录文本用于调研
- 02重复处理视频而无需再次抓取
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ gooseworks-ai/ goose-skills --skill youtube-apify-transcript安装后在 Claude Code 中输入/youtube-apify-transcript确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
CHANGELOG.mdpackage.jsonREADME.mdskill.meta.jsonscripts/fetch_transcript.py详细介绍
youtube-apify-transcript
通过 APIFY API 获取 YouTube 字幕稿(可在云 IP 上使用,绕过 YouTube 的机器人检测)。
为什么选择 APIFY?
YouTube 会阻止来自云 IP(AWS、GCP 等)的字幕稿请求。APIFY 通过住宅代理发送请求,可可靠地绕过机器人检测。
免费套餐
- 每月 $5 免费额度(约 714 个视频)
- 无需信用卡
- 非常适合个人使用
费用
- 每个视频 $0.007(不到 1 美分!)
- 在此处跟踪用量:https://console.apify.com/billing
链接
设置
- 创建免费的 APIFY 账号:https://apify.com/
- 获取 API 令牌:https://console.apify.com/account/integrations
- 设置环境变量:
# Add to ~/.bashrc or ~/.zshrc
export APIFY_API_TOKEN="apify_api_YOUR_TOKEN_HERE"
# Or use .env file (never commit this!)
echo 'APIFY_API_TOKEN=apify_api_YOUR_TOKEN_HERE' >> .env
使用方法
基本用法
# Get transcript as text (uses cache by default)
python3 scripts/fetch_transcript.py "https://www.youtube.com/watch?v=VIDEO_ID"
# Short URL also works
python3 scripts/fetch_transcript.py "https://youtu.be/VIDEO_ID"
选项
# Output to file
python3 scripts/fetch_transcript.py "URL" --output transcript.txt
# JSON format (includes timestamps)
python3 scripts/fetch_transcript.py "URL" --json
# Both: JSON to file
python3 scripts/fetch_transcript.py "URL" --json --output transcript.json
# Specify language preference
python3 scripts/fetch_transcript.py "URL" --lang de
缓存(省钱!)
默认情况下,字幕稿会缓存在本地。重复请求同一个视频无需付费。
# First request: fetches from APIFY ($0.007)
python3 scripts/fetch_transcript.py "URL"
# Second request: uses cache (FREE!)
python3 scripts/fetch_transcript.py "URL"
# Output: [cached] Transcript for: VIDEO_ID
# Bypass cache (force fresh fetch)
python3 scripts/fetch_transcript.py "URL" --no-cache
# View cache stats
python3 scripts/fetch_transcript.py --cache-stats
# Clear all cached transcripts
python3 scripts/fetch_transcript.py --clear-cache
缓存位置:技能目录中的 .cache/(可通过 YT_TRANSCRIPT_CACHE_DIR 环境变量覆盖)
批量模式
一次处理多个视频:
# Create a file with URLs (one per line)
cat > urls.txt << EOF
https://youtube.com/watch?v=VIDEO1
https://youtu.be/VIDEO2
https://youtube.com/watch?v=VIDEO3
EOF
# Process all URLs
python3 scripts/fetch_transcript.py --batch urls.txt
# Batch with JSON output to file
python3 scripts/fetch_transcript.py --batch urls.txt --json --output all_transcripts.json
APIFY Actor 输入
脚本会向 pintostudio/youtube-transcript-scraper 发送以下输入:
{
"videoUrl": "https://www.youtube.com/watch?v=VIDEO_ID"
}
输出字段:
每个结果都包含一个由字幕片段组成的 data 数组:
| 字段 | 类型 | 描述 |
|---|---|---|
start | number | 片段开始时间(秒) |
dur | number | 片段时长(秒) |
text | string | 此片段的字幕文本 |
输出格式
文本(默认):
Hello and welcome to this video.
Today we're going to talk about...
JSON(--json):
{
"video_id": "dQw4w9WgXcQ",
"title": "Video Title",
"transcript": [
{"start": 0.0, "dur": 2.5, "text": "Hello and welcome"},
{"start": 2.5, "dur": 3.0, "text": "to this video"}
],
"full_text": "Hello and welcome to this video..."
}
错误处理
脚本会处理常见错误:
- 无效的 YouTube URL
- 视频没有字幕稿
- API 配额超限
- 网络错误
评论
支持 Markdown