编程

youtube-apify-transcript

试用

从云服务器环境获取 YouTube 视频转录文本,绕过 YouTube 的反爬检测。

它能做什么

通过 Apify 接口拉取 YouTube 视频转录文本,借助住宅代理绕过 YouTube 对云 IP(如 AWS、GCP、Hetzner)的拦截。本地缓存让重复请求零成本,批量模式可一次处理一个 URL 列表。支持纯文本与带时间戳的 JSON 输出,可指定优先语言。Apify 新账号每月 $5 免费额度(约 714 个视频),超出部分按 $0.007/视频 计费。

什么时候用它

  • 在云服务器或无服务器环境中抓取 YouTube 字幕
  • 批量获取一组视频的转录文本
  • 通过本地缓存避免对同一视频重复计费
  • 导出带时间戳的 JSON 转录用于后续处理

技能文档

youtube-apify-transcript

Fetch YouTube transcripts via APIFY API (works from cloud IPs, bypasses YouTube bot detection).

Why APIFY?

YouTube blocks transcript requests from cloud IPs (AWS, GCP, etc.). APIFY runs the request through residential proxies, bypassing bot detection reliably.

Free Tier

  • $5/month free credits (~714 videos)
  • No credit card required
  • Perfect for personal use

Cost

Setup

  1. Create free APIFY account: https://apify.com/
  2. Get your API token: https://console.apify.com/account/integrations
  3. Set environment variable:
# Add to ~/.bashrc or ~/.zshrc
export APIFY_API_TOKEN="apify_api_YOUR_TOKEN_HERE"

# Install Python dependency
pip install requests

# Or use .env file (never commit this!)
echo 'APIFY_API_TOKEN=apify_api_YOUR_TOKEN_HERE' >> .env

Usage

Basic Usage

# 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"

Options

# 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

Caching (saves money!)

Transcripts are cached locally by default. Repeat requests for the same video cost $0.

# 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 location: .cache/ in skill directory (override with YT_TRANSCRIPT_CACHE_DIR env var)

Batch Mode

Process multiple videos at once:

# 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

# Output: 
# [1/3] Fetching VIDEO1...
# [2/3] [cached] VIDEO2
# [3/3] Fetching VIDEO3...
# Batch complete: 2 fetched, 1 cached, 0 failed
# [Cost: ~$0.014 for 2 API call(s)]

# Batch with JSON output to file
python3 scripts/fetch_transcript.py --batch urls.txt --json --output all_transcripts.json

Output Formats

Text (default):

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, "duration": 2.5, "text": "Hello and welcome"},
    {"start": 2.5, "duration": 3.0, "text": "to this video"}
  ],
  "full_text": "Hello and welcome to this video..."
}

Agent Instructions

When the user asks to summarize a YouTube video, first fetch the transcript using the script, then summarize the transcript text directly using your own model capabilities. Do NOT use --summarize flag.

Error Handling

The script handles common errors:

  • Invalid YouTube URL
  • Video has no transcript
  • API quota exceeded
  • Network errors

Metadata

metadata:
  clawdbot:
    emoji: "📹"
    requires:
      env: ["APIFY_API_TOKEN"]
      bins: ["python3"]
      python:
        packages: ["requests"]

常见问题

为什么不直接请求 YouTube,而是走 Apify?
YouTube 会拦截来自云 IP 的转录请求。Apify 通过住宅代理转发请求,从而稳定绕过 AWS、GCP 等环境中的反爬检测。
使用成本是多少?
未命中缓存的视频按 $0.007/次 计费。Apify 新账号每月赠送 $5 免费额度,约可处理 714 个视频;同一视频的重复请求走本地缓存,零费用。
需要哪些前置依赖?
需要一个 Apify 账号并将 token 导出为环境变量 APIFY_API_TOKEN,环境中要有 python3,并安装 requests 库。脚本调用的是 topaz_sharingan/Youtube-Transcript-Scraper-1 这个 Apify Actor。

相关技能

以 AI 机器人身份加入视频会议,提供语音、虚拟形象与屏幕共享四种模式。

作者 johnpatternai21 次安装8 星标

在本地磁盘以分类纯 Markdown 文件保存需要长期留存的事实,与智能体内置记忆并存。

作者 Iván555 次安装18 星标

从 AdMapix API 拉取广告创意、应用、榜单和收入预估等数据,原样返回结构化 JSON。

作者 fly0pants4.3k 次安装296 星标

诊断生产力系统反复失效的根因,给出最小干预——容量测算、瓶颈定位、可靠的本地记录。

作者 Iván854 次安装69 星标

按用户明确指令,在得到大脑(Get笔记)中保存、搜索并管理笔记与知识库。

作者 iswalle763 次安装66 星标

robbyczgw-cla 的更多技能

浏览全部技能

让 Agent 自动生成 400–600 字的第一人称反思日记,并跟踪金句、决策与心情趋势。

作者 robbyczgw-cla208 次安装6 星标

跨网页搜索、RSS/Atom 订阅和 GitHub 发布持续追踪主题,仅在出现相关内容时推送提醒。

作者 robbyczgw-cla366 次安装27 星标

调用 ElevenLabs API,提供 18 种人声角色、32 种语言合成、音效生成与自定义人声设计。

作者 robbyczgw-cla275 次安装16 星标

三位专家子代理并行作答,再可选互相质询,最终输出一份带共识、异议与置信度的综合答案。

作者 robbyczgw-cla62 次安装2 星标

在任意 AI 回复后,基于上下文生成三条追问建议:快速澄清、深入探索、相关话题。

作者 robbyczgw-cla192 次安装8 星标

随时切换到 20 个内置 AI 人格,覆盖编程、写作、健身、医法科普等场景。

作者 robbyczgw-cla282 次安装27 星标