Skip to content

About

A 100% automated pipeline for scripting, narrating, editing, and posting videos to YouTube

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

yt-factory

Automated YouTube video generation, upload, and optimization pipeline. A production-ready CLI tool for creating faceless YouTube channels with intelligent content selection, A/B testing, and adaptive learning.

Features

  • Channel Blueprints: YAML-based configuration with Zod validation
  • Dual-Format Support: Shorts (< 60s) and Longform videos with auto-switching
  • Multi-Stage Pipeline: Research → Plan → Script → TTS → Visuals → Edit → Package → Upload → A/B Test → Report
  • Adaptive Learning: Daily analytics processing with winner/loser detection and policy weight updates
  • Scheduler Daemon: Ramp-up phases, jitter, caps, and emergency stop
  • Compliance System: Niche classification, safety filtering, and fact verification
  • Originality System: Cooldowns, diversity constraints, and similarity detection
  • A/B Testing: Bayesian CTR analysis for thumbnails and titles
  • Cost Estimation: Pre-run estimates and post-run tracking
  • Shadow Mode: Unlisted QA publishing before going public
  • Rights Ledger: Asset usage tracking with attribution

Requirements

  • Node.js 20+
  • FFmpeg (for video editing)
  • API keys for providers (OpenAI, ElevenLabs, Pexels, YouTube)

Installation

# Clone the repository
git clone https://github.com/your-org/yt-factory.git
cd yt-factory

# Install dependencies
npm install

# Build
npm run build

# Link globally (optional)
npm link

Quick Start

# 1. Initialize project structure
yt-factory init

# 2. Configure environment variables
#    Edit .env with your API keys

# 3. Create a channel blueprint
yt-factory blueprint init --preset nature_facts --slug my-nature-channel

# 4. Validate the blueprint
yt-factory blueprint validate --channel my-nature-channel

# 5. Estimate costs before running
yt-factory estimate --channel my-nature-channel --format short --count 5

# 6. Run a single video
yt-factory run --channel my-nature-channel --prompt "fascinating facts about octopuses"

# 7. Start the scheduler for automated publishing
yt-factory schedule start --channel my-nature-channel

Configuration

Environment Variables (.env)

# LLM Provider
OPENAI_API_KEY=sk-...
OPENAI_MODEL=gpt-4o

# Text-to-Speech
ELEVENLABS_API_KEY=...
ELEVENLABS_VOICE_ID=...

# Visuals
PEXELS_API_KEY=...

# YouTube
YOUTUBE_CLIENT_ID=...
YOUTUBE_CLIENT_SECRET=...
YOUTUBE_REFRESH_TOKEN=...

# Research (optional)
TAVILY_API_KEY=...

# YouTube Analytics (optional)
YOUTUBE_ANALYTICS_ENABLED=true

Config File (config.yaml)

providers:
  llm:
    type: openai
    model: gpt-4o
  tts:
    type: elevenlabs
    voiceId: your-voice-id
  visual:
    type: pexels
  music:
    type: royalty_free
  upload:
    type: youtube

database:
  path: ./data/yt-factory.db

output:
  directory: ./out

logging:
  level: info
  file: ./logs/yt-factory.log

Channel Blueprints

Blueprints define your channel's content strategy, rules, and constraints.

Creating a Blueprint

# Use a preset
yt-factory blueprint init --preset nature_facts --slug wildlife-daily

# List existing blueprints
yt-factory blueprint list

# Validate a blueprint
yt-factory blueprint validate --channel wildlife-daily

# Validate with a specific prompt
yt-factory blueprint validate --channel wildlife-daily --prompt "why do birds migrate"

Blueprint Structure

Blueprints are stored in ./channels/{slug}/blueprint.yaml:

version: "1.0"

channel:
  name: "Nature Facts Daily"
  description: "Fascinating nature facts for curious minds"

niche:
  id: nature_facts
  description: "Educational nature content"
  allowedTopics:
    - wildlife
    - marine_life
    - ecosystems
  forbiddenTopics:
    - hunting
    - animal_cruelty

format:
  type: shorts
  shorts:
    targetDuration: 45
    maxDuration: 58

contentRules:
  tone: educational_engaging
  targetAudience: general
  monetizationSafe: true

starterTopicFamilies:
  families:
    - id: marine_wonders
      themes:
        - "Deep sea creatures"
        - "Coral reef ecosystems"
      angles:
        - surprising_adaptation
        - record_holder

templateLibrary:
  shortsTemplates:
    - id: fact_rapid
      name: "Rapid Facts"
      structure:
        hookStyle: question
        pacing: fast

publishing:
  selectedPreset: conservative
  cadencePresets:
    - name: conservative
      shortsMaxPerDay: 2
      longformMaxPerDay: 0
      maxPublishesPerDay: 2

shadowMode:
  enabled: true
  minUnlistedViews: 100
  minWatchTimePercent: 40

safetyControls:
  costControls:
    dailyBudgetUSD: 25
    monthlyBudgetUSD: 300

Pipeline Stages

The video generation pipeline consists of 10 stages:

  1. Research: Gather viral best practices and trending topics
  2. Plan: Generate video outline with sections and timings
  3. Script: Write narration script with hooks and CTAs
  4. TTS: Convert script to speech audio
  5. Visuals: Source stock footage and images
  6. Edit: Assemble video with FFmpeg
  7. Packaging: Generate thumbnails and metadata variations
  8. Upload: Publish to YouTube (or save locally)
  9. A/B Testing: Set up and monitor variant tests
  10. Report: Generate job summary and costs

Checkpointing

Jobs are checkpointed after each stage. If a job fails, it can be resumed:

# List resumable jobs
yt-factory resume --list

# Resume a specific job
yt-factory resume --job abc123

# Resume latest for a channel
yt-factory resume --channel my-channel

Scheduler

The scheduler daemon handles automated content publishing with safety controls.

Ramp-Up Phases

New channels start with conservative publishing and gradually increase:

Phase Duration Max/Day
1 Days 1-7 1
2 Days 8-14 2
3 Days 15-21 3
4 Day 22+ Preset max

Commands

# Start the scheduler
yt-factory schedule start --channel my-channel

# Check status
yt-factory schedule status
yt-factory schedule status --channel my-channel

# Pause/resume
yt-factory schedule pause --channel my-channel --reason "maintenance"
yt-factory schedule resume --channel my-channel

# Preview daily plan
yt-factory schedule plan --channel my-channel

Emergency Stop

# Stop a channel immediately
yt-factory emergency stop --channel my-channel --reason "content issue"

# Stop all channels
yt-factory emergency stop --reason "system maintenance"

# Full lockdown
yt-factory emergency lockdown --reason "critical issue" --confirm

# Check status
yt-factory emergency status

# Clear emergency stop
yt-factory emergency clear --channel my-channel --confirm

Analytics & Learning

The analytics brain processes YouTube metrics daily to improve content selection.

How It Works

  1. Sync Metrics: Pull views, watch time, CTR, engagement from YouTube Analytics
  2. Classify Performance: Identify winners (>1.5x median) and losers (<0.5x median)
  3. Generate Signals: Create learning signals for templates and topic families
  4. Update Weights: Adjust policy weights using gradient descent

Commands

# Sync analytics data
yt-factory analytics sync --channel my-channel --days 7

# Run daily analysis
yt-factory analytics daily --channel my-channel

# Generate report
yt-factory analytics report --channel my-channel --period weekly

# View specific video
yt-factory analytics video --video VIDEO_ID

Learning System

# View learning status
yt-factory learning status --channel my-channel

# View policy weights
yt-factory learning weights --channel my-channel --sort weight

# Reset learning (start fresh)
yt-factory learning reset --channel my-channel --all --confirm

# Export learning data
yt-factory learning export --channel my-channel > learning.json

A/B Testing

Automatic variant testing for thumbnails and titles.

Configuration

abTesting:
  thumbnailTesting:
    enabled: true
    variants: 3
  titleTesting:
    enabled: true
    variants: 2
  algorithm: bayesian
  minSampleSize: 100
  confidenceThreshold: 0.9
  maxTestDurationHours: 72

Commands

# View A/B test status
yt-factory ab status --channel my-channel

# Analyze a specific test
yt-factory ab analyze --test TEST_ID

# Manually decide a winner
yt-factory ab decide --test TEST_ID --winner variant_a

# View test history
yt-factory ab history --channel my-channel

Template Management

Templates define video structures for consistent output.

# List templates
yt-factory templates list --channel my-channel

# Show template details
yt-factory templates show --channel my-channel --id fact_rapid

# Add a new template
yt-factory templates add --channel my-channel --format short \
  --id quick_list --name "Quick List" \
  --hook statement --pacing fast --cta end

# Remove a template
yt-factory templates remove --channel my-channel --id old_template --confirm

# View usage statistics
yt-factory templates usage --channel my-channel

Cost Management

Track and control API spending.

Pre-Run Estimation

# Estimate single video
yt-factory estimate --channel my-channel --format short

# Estimate batch
yt-factory estimate --channel my-channel --format short --count 10

Budget Controls

Set in blueprint.yaml:

safetyControls:
  costControls:
    dailyBudgetUSD: 25
    monthlyBudgetUSD: 300
    alertThresholdPercent: 80

The pipeline will refuse to run if:

  • Estimated cost would exceed daily budget
  • Monthly spending is at capacity

Shadow Mode

Test videos as unlisted before public release.

How It Works

  1. Videos are published as unlisted initially
  2. Share link in controlled community for testing
  3. Monitor metrics against thresholds
  4. Promote to public when thresholds met

Configuration

shadowMode:
  enabled: true
  minUnlistedViews: 100
  minWatchTimePercent: 40
  minDaysUnlisted: 1
  autoPromote: true

Running in Shadow Mode

# Force shadow mode for a run
yt-factory run --channel my-channel --prompt "..." --shadow

Fact Verification

Automatic fact-checking with citations.

Configuration

factVerification:
  enabled: true
  sources:
    - wikipedia
    - scientific_journals
  minConfidence: 0.8
  requireCitations: true

Facts are verified during the script stage. Low-confidence claims are flagged or removed.

Rights Ledger

Track asset usage and attribution.

Every video maintains a rights ledger of:

  • Stock footage sources and licenses
  • Music tracks and attribution
  • Font licenses
  • AI model usage

Project Structure

yt-factory/
├── channels/           # Channel blueprints
│   └── {slug}/
│       └── blueprint.yaml
├── out/                # Generated videos
│   └── {slug}/
│       └── {jobId}/
├── data/               # SQLite database
├── credentials/        # OAuth tokens
├── assets/
│   ├── music/         # Royalty-free music
│   └── stock/         # Stock footage cache
├── logs/              # Application logs
└── src/
    ├── cli/           # CLI commands
    ├── core/          # Core business logic
    │   ├── blueprint/ # Schema & validation
    │   ├── compliance/# Niche, safety, facts
    │   ├── cost/      # Estimation & tracking
    │   ├── learning/  # Analytics brain
    │   ├── originality/# Diversity & similarity
    │   ├── pipeline/  # Job runner & stages
    │   └── scheduler/ # Daemon & planner
    ├── db/            # SQLite & models
    ├── providers/     # External services
    └── utils/         # Helpers

YouTube OAuth Setup

  1. Create a project in Google Cloud Console
  2. Enable YouTube Data API v3 and YouTube Analytics API
  3. Create OAuth 2.0 credentials (Desktop app)
  4. Download credentials and place in ./credentials/oauth.json
  5. Run the auth flow:
# First run will open browser for OAuth consent
yt-factory run --channel my-channel --prompt "test" --dry-run
  1. Refresh token is saved automatically

Monetization Safety

The system includes guardrails for advertiser-friendly content:

  • Allowed topics: Defined in niche configuration
  • Forbidden topics: Explicitly blocked
  • Safety filter: Checks for policy violations
  • Tone enforcement: Maintains family-friendly language
  • Content review: Optional human review queue

Development

# Run in development
npm run dev

# Run tests
npm test

# Lint
npm run lint

# Type check
npm run typecheck

Troubleshooting

Common Issues

"Blueprint validation failed"

  • Check YAML syntax
  • Ensure all required fields are present
  • Run yt-factory blueprint validate --channel <slug>

"Prompt is OUT OF NICHE"

  • Review allowed/forbidden topics in blueprint
  • Use more specific, on-topic prompts

"Would exceed daily budget"

  • Wait for budget reset (midnight UTC)
  • Increase dailyBudgetUSD in blueprint
  • Use --dry-run to estimate without spending

"No YouTube credentials"

  • Complete OAuth setup
  • Check YOUTUBE_* environment variables
  • Verify refresh token is valid

Logs

# View recent logs
tail -f logs/yt-factory.log

# Filter by level
grep "ERROR" logs/yt-factory.log

License

MIT

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Submit a pull request

See CONTRIBUTING.md for guidelines.

About

A 100% automated pipeline for scripting, narrating, editing, and posting videos to YouTube

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages