youtube-apify-transcript について
Apify APIを使ってYouTube動画の文字起こしを取得するコマンドラインスキルです。YouTubeがリクエストをブロックする可能性のあるクラウド環境にも対応し、ローカルキャッシュ、テキストやタイムスタンプ付きJSONの出力、一括処理を備えています。
主な機能
- 01Apify経由で文字起こしを取得
- 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 本の動画)
- クレジットカードは不要です
- 個人利用に最適です
料金
- 動画 1 本あたり $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
キャッシュ(費用を節約できます!)
文字起こしはデフォルトでローカルにキャッシュされます。同じ動画への再リクエストは $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/(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 | 数値 | セグメントの開始時刻(秒) |
dur | 数値 | セグメントの長さ(秒) |
text | 文字列 | このセグメントの文字起こしテキスト |
出力形式
テキスト(デフォルト):
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 対応