Fetch transcripts from YouTube videos. Use when the user shares a YouTube URL, references a video, wants to know what someone said in a video, or needs video content as text.
Fetch transcripts from any YouTube video. No API key required.
Parse the YouTube URL to extract the video ID. Handle these formats:
https://www.youtube.com/watch?v=VIDEO_IDhttps://youtu.be/VIDEO_IDVIDEO_ID (direct ID)Run this single command that handles installation and fetching in one shot:
python3 -c "
try:
from youtube_transcript_api import YouTubeTranscriptApi
except ImportError:
import subprocess, sys
try:
subprocess.check_call([sys.executable, '-m', 'pip', 'install', '--user', '-q', 'youtube-transcript-api'])
except subprocess.CalledProcessError:
subprocess.check_call([sys.executable, '-m', 'pip', 'install', '--break-system-packages', '-q', 'youtube-transcript-api'])
from youtube_transcript_api import YouTubeTranscriptApi
def fmt_time(seconds):
m, s = divmod(int(seconds), 60)
h, m = divmod(m, 60)
return f'{h}:{m:02d}:{s:02d}' if h else f'{m}:{s:02d}'
api = YouTubeTranscriptApi()
transcript = api.fetch('VIDEO_ID')
# Print with timestamps every ~30 seconds for navigation
last_ts = -30
for entry in transcript:
if entry.start - last_ts >= 30:
print(f'\n[{fmt_time(entry.start)}]')
last_ts = entry.start
print(entry.text)
"
Replace VIDEO_ID with the extracted ID.
Features:
If you just need raw text without any timestamps:
python3 -c "
try:
from youtube_transcript_api import YouTubeTranscriptApi
except ImportError:
import subprocess, sys
try:
subprocess.check_call([sys.executable, '-m', 'pip', 'install', '--user', '-q', 'youtube-transcript-api'])
except subprocess.CalledProcessError:
subprocess.check_call([sys.executable, '-m', 'pip', 'install', '--break-system-packages', '-q', 'youtube-transcript-api'])
from youtube_transcript_api import YouTubeTranscriptApi
api = YouTubeTranscriptApi()
transcript = api.fetch('VIDEO_ID')
for entry in transcript:
print(f"{entry.start}: {entry.text}")
"
Present the transcript with:
If the transcript fetch fails:
python3 -c "
from youtube_transcript_api import YouTubeTranscriptApi
api = YouTubeTranscriptApi()
transcript_list = api.list(video_id='VIDEO_ID')
print('Available transcripts:')
for t in transcript_list:
print(f' - {t.language} ({t.language_code})')
"
Requires youtube-transcript-api Python package. The fetch script auto-installs it on first run, handling:
--user install)--break-system-packages fallback)Manual install if needed:
pip3 install --user youtube-transcript-api
# or on macOS with Homebrew Python:
pip3 install --break-system-packages youtube-transcript-api