Skip to main content

YouTube transcripts to RAG-ready volumes

Project description

ytrag

YouTube transcripts → RAG-ready volumes.

Download YouTube subtitles, clean them to markdown, and consolidate them into LLM-ready volumes.

Quick Start

# Install from GitHub
pip install git+https://github.com/chakkyy/ytrag.git

# Download and process a YouTube channel
ytrag all "https://youtube.com/@ChannelName"

That's it! The transcripts will be cleaned and organized into volumes ready for use with LLMs.

Installation

From GitHub (recommended)

pip install git+https://github.com/chakkyy/ytrag.git

From Source

git clone https://github.com/chakkyy/ytrag.git
cd yt-scraper
pip install .

With pipx (isolated environment)

pipx install git+https://github.com/chakkyy/ytrag.git

Usage

Full Pipeline (recommended)

Process an entire YouTube channel in one command:

ytrag all "https://youtube.com/@ChannelName"

This will:

  1. Download all available subtitles
  2. Clean VTT files to readable markdown
  3. Consolidate into LLM-ready volumes

Individual Commands

Run each step separately if needed:

# Download subtitles only
ytrag download "https://youtube.com/@ChannelName"

# Clean VTT files to markdown
ytrag clean

# Consolidate to volumes
ytrag consolidate

Command Options

# Specify languages (default: es,en)
ytrag all "https://..." --lang es,en,pt

# Custom output directory
ytrag all "https://..." --output ./my-transcripts

# Adjust transcripts per volume (default: 100)
ytrag all "https://..." --per-volume 50

# Check status of current directory
ytrag status

# Show version
ytrag --version

# Show all commands and options
ytrag --help

Programmatic Usage

You can also use ytrag as a Python library:

from pathlib import Path
from ytrag.downloader import Downloader
from ytrag.utils import create_subtitle_callback

# Setup output directory
output_dir = Path("./transcripts")

# Create callback to clean subtitles as they download
callback = create_subtitle_callback(output_dir, verbose=True)

# Initialize downloader
downloader = Downloader(output_dir, on_subtitle_downloaded=callback)

# Download subtitles
stats = downloader.download("https://youtube.com/@ChannelName", langs=["en", "es"])
print(f"Downloaded: {stats['downloaded']}, Errors: {stats['errors']}")

For consolidation:

from ytrag.consolidator import consolidate_all

# Consolidate cleaned transcripts into volumes
manifest = consolidate_all(
    base_dir=".",  # Directory containing _biblioteca/
    transcripts_per_volume=100
)
print(f"Processed channels: {list(manifest['channels'].keys())}")

Output Structure

After running ytrag all, your directory will look like:

./
├── ChannelName/                    # Raw VTT files
│   ├── 20230101_Video Title.en.vtt
│   └── ...
├── _biblioteca/                    # Cleaned markdown
│   └── ChannelName/
│       └── 20230101_Video Title [EN].md
├── _exports/                       # LLM-ready volumes
│   ├── ChannelName_Vol01.txt
│   ├── ChannelName_Vol02.txt
│   └── manifest.json
└── .ytrag_archive.txt              # Resume tracking

What Each Folder Contains

Folder Purpose
ChannelName/ Raw subtitle files (VTT format)
_biblioteca/ Individual cleaned transcripts (Markdown)
_exports/ Consolidated volumes ready for LLMs

Examples

Process a Single Video

ytrag all "https://www.youtube.com/watch?v=dQw4w9WgXcQ"

Process a Playlist

ytrag all "https://www.youtube.com/playlist?list=PLxxxxxxx"

Process a Channel

ytrag all "https://youtube.com/@ChannelName"

Spanish-Only Transcripts

ytrag all "https://youtube.com/@ChannelName" --lang es

Features

  • Stream processing: Files are cleaned as they download
  • Adaptive rate limiting: Automatically handles YouTube rate limits
  • Resume support: Re-run to continue where you left off
  • Smart deduplication: Skips regional variants (en-US if en exists)
  • Subtitle priority: Prefers manual > auto-original > skips translated

Requirements

  • Python 3.10+

Troubleshooting

"No subtitles found"

Some videos don't have subtitles enabled. Try:

  • Using --lang with different language codes
  • Using auto-generated subtitles (these are downloaded by default)

Rate limiting errors

YouTube may rate-limit downloads. ytrag handles this automatically with exponential backoff, but for large channels you may need to wait or run again later.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ytrag-1.0.0.tar.gz (27.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ytrag-1.0.0-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file ytrag-1.0.0.tar.gz.

File metadata

  • Download URL: ytrag-1.0.0.tar.gz
  • Upload date:
  • Size: 27.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for ytrag-1.0.0.tar.gz
Algorithm Hash digest
SHA256 526c99f9845efc21af78b44c70eb6a47bce89044174c045f72b709a1c5700d35
MD5 46149851b49d03e609540ead09971cc9
BLAKE2b-256 8b5db0c4e6c2672230f06fda8ffea3c626b07003f0f19840151e763047fa5403

See more details on using hashes here.

File details

Details for the file ytrag-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: ytrag-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 15.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for ytrag-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 33e46cbca0dd2542853ef9e22faab6e679688bed1c7c3abeec43a38411a52419
MD5 2af1de257003c0d08b58c05e12e928fd
BLAKE2b-256 877d97f234fcf21fe02bcbc219dc35be30c3edeb0e4f2996735ecb34ecda2d85

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page