A command-line tool to fetch and save YouTube video transcripts in plain text or SRT format, using yt-dlp and supporting cookies for private or age-restricted videos.
- Extracts transcripts from YouTube videos (supports both manual and auto-generated captions)
- Output formats: plain text (
.txt) or SRT (.srt) - Handles cookies from browser or file for restricted videos
- Saves output to the
output/directory
- Clone the repository:
git clone https://github.com/juliustnt/transcript_scraper.git cd transcript_scraper - Install dependencies:
This will install
pip install -e .yt-dlpandrequestsas required dependencies.
Run the CLI tool with:
ytx-transcript <YouTube URL or ID> [plain|srt] [--cookies <cookies.txt>] [--browser <browser>] [--no-browser-cookies]<YouTube URL or ID>: The video to fetch the transcript from[plain|srt]: Output format (default:plain)--input <PATH>: Path to a text file containing multiple YouTube URLs/IDs (one per line). Mutually exclusive with<YouTube URL or ID>--cookies <cookies.txt>: Path to a cookies.txt file (Netscape format)--browser <browser>: Try to use cookies from a browser (edge,chrome,firefox,brave,vivaldi,chromium)--no-browser-cookies: Never attempt to use browser cookies
Fetch a transcript in plain text:
ytx-transcript https://www.youtube.com/watch?v=dQw4w9WgXcQFetch a transcript in SRT format and save using Chrome cookies:
ytx-transcript https://www.youtube.com/watch?v=dQw4w9WgXcQ srt --browser chrome- Transcripts are saved in the
output/directory, named after the video ID and format (e.g.,dQw4w9WgXcQ.txtordQw4w9WgXcQ.srt).
transcript_scraper/
├── pyproject.toml
├── README.md
├── output/
└── src/
└── ytx/
├── __init__.py
├── captions.py
├── cli.py
├── io_utils.py
└── parse.py