Metadata-Version: 2.4
Name: youtube-factory-pipeline
Version: 0.2.1
Summary: Modular pipeline agents for automated YouTube video production
Author-email: bgill55 <bgill55@users.noreply.github.com>
License: MIT License
        
        Copyright (c) 2026 bgill55
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
Project-URL: Homepage, https://github.com/bgill55/youtube-factory-pipeline
Project-URL: Repository, https://github.com/bgill55/youtube-factory-pipeline
Project-URL: Issues, https://github.com/bgill55/youtube-factory-pipeline/issues
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Multimedia :: Video
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: httpx>=0.25
Requires-Dist: python-dotenv>=1.0
Requires-Dist: google-api-python-client>=2.100
Requires-Dist: google-auth-oauthlib>=1.1
Requires-Dist: google-auth-httplib2>=0.1
Requires-Dist: pillow>=10.0
Requires-Dist: numpy>=1.24
Requires-Dist: croniter>=2.0
Requires-Dist: requests>=2.31
Requires-Dist: feedparser>=6.0
Requires-Dist: yt-dlp>=2024.0
Requires-Dist: agent-reach>=1.5.0
Provides-Extra: omnivoice
Requires-Dist: torch>=2.0; extra == "omnivoice"
Requires-Dist: torchaudio>=2.0; extra == "omnivoice"
Provides-Extra: stable-audio
Requires-Dist: torch>=2.0; extra == "stable-audio"
Requires-Dist: transformers>=4.30; extra == "stable-audio"
Requires-Dist: soundfile>=0.12; extra == "stable-audio"
Provides-Extra: dev
Requires-Dist: pytest>=7.4; extra == "dev"
Requires-Dist: ruff>=0.1; extra == "dev"
Requires-Dist: mypy>=1.0; extra == "dev"
Provides-Extra: all
Requires-Dist: torch>=2.0; extra == "all"
Requires-Dist: torchaudio>=2.0; extra == "all"
Requires-Dist: transformers>=4.30; extra == "all"
Requires-Dist: soundfile>=0.12; extra == "all"
Dynamic: license-file

# YouTube Factory Pipeline

**Modular, provider-agnostic agents for automated YouTube video production.**

[![PyPI](https://img.shields.io/pypi/v/youtube-factory-pipeline.svg)](https://pypi.org/project/youtube-factory-pipeline/)
[![Python](https://img.shields.io/pypi/pyversions/youtube-factory-pipeline.svg)](https://pypi.org/project/youtube-factory-pipeline/)
[![License](https://img.shields.io/pypi/l/youtube-factory-pipeline.svg)](https://pypi.org/project/youtube-factory-pipeline/)

---

## Overview

`youtube-factory-pipeline` is the **core orchestration library** behind the "Weight and See" YouTube channel. It provides a clean, modular set of agents that handle every stage of video production:

```
Research → Idea Generation → Script Writing → Voiceover → Visuals → 
Audio Generation → Assembly → Shorts → Upload → Guide Deployment
```

Each agent is **independently usable**, **provider-agnostic**, and **configured via a single JSON file**.

---

## Features

| Agent | Purpose | Key Capability |
|-------|---------|----------------|
|| `ResearchAgent` | GitHub/HF/arXiv/web/YouTube/RSS/semantic search | Structured JSON briefs via Agent Reach (yt-dlp, Jina Reader, gh CLI, Exa MCP, feedparser) |
| `IdeaGeneratorAgent` | Video concept + SWOT | 3 concepts → 1 selected, niche diversity enforced |
| `ScriptwriterAgent` | 3-act retention scripts | Hook → Breakdown → Deep Dive + CTA |
|| `VoiceoverAgent` | TTS via OmniVoice/Edge/Supertonic | Multi-speaker, word-level timestamps, CPU-only Supertonic M4 |
| `VisualAssetAgent` | B-roll + AI images + thumbnails | Pexels / SD / Fal / Pollinations / local |
| `AudioGenAgent` | BGM via Stable Audio 3 | Ducking, volume automation |
| `VideoAssemblerAgent` | FFmpeg assembly | Subtitles, ducking, 4K output |
| `ShortGenerator` | 9:16 vertical clips | Auto-scene selection ≤58s |
| `UploaderAgent` | YouTube Data API v3 | Playlists, thumbnails, Shorts |
| `GuideGeneratorAgent` | HTML resource pages | SEO-optimized, deployable to GitHub Pages |
| `CommunityAgent` | YouTube Community posts | Auto-generated from video outputs |

---

## Installation

```bash
# Core dependencies only
pip install youtube-factory-pipeline

# With optional providers
pip install "youtube-factory-pipeline[omnivoice]"      # Local TTS
pip install "youtube-factory-pipeline[stable-audio]"  # BGM generation
pip install "youtube-factory-pipeline[all]"           # Everything
```

---

## Quickstart

```python
from youtube_factory.orchestrator import PipelineOrchestrator
from youtube_factory.config import load_config

# Load your config (see Configuration below)
config = load_config("path/to/config.json")

# Create orchestrator
orchestrator = PipelineOrchestrator(workspace_dir="~/youtube_factory")

# Start a run
run_id, state = orchestrator.create_new_run(
    topic_seed="Ollama 0.9.0 local LLM benchmark",
    target_audience="Tech enthusiasts",
    competitor_analysis="Existing LM Studio reviews"
)

# Execute full pipeline (runs in background thread)
orchestrator.execute(run_id)

# Or run individual stages
from youtube_factory.agents.idea import IdeaGeneratorAgent
idea_agent = IdeaGeneratorAgent(config)
result = idea_agent.run({
    "topic_seed": "...",
    "target_audience": "...",
    "competitor_analysis": "..."
})
```

---

## Configuration

All agents read from a single `config.json` with environment variable interpolation (`${VAR}`):

```json
{
  "freellmapi": {
    "api_key": "${FREELLAPI_KEY}",
    "base_url": "http://localhost:3001/v1",
    "timeout": 120
  },
  "omnivoice": {
    "base_url": "http://localhost:3900/v1",
    "voice_id": "brian_ref"
  },
  "supertonic": {
    "base_url": "http://127.0.0.1:7788",
    "voice_name": "M4",
    "total_steps": 8,
    "speed": 1.05
  },
  "pexels_api_key": "${PEXELS_API_KEY}",
  "local_sd": {
    "base_url": "http://127.0.0.1:7860",
    "lora_url": "https://.../style.safetensors"
  },
  "video_settings": { "width": 1920, "height": 1080 },
  "upload_settings": { "privacy_status": "private" }
}
```

Environment variables loaded from `.env`:
```bash
FREELLAPI_KEY=freellmapi-xxx
PEXELS_API_KEY=xxx
GEMINI_API_KEY=xxx
# etc.
```

---

## Architecture

```
┌─────────────────────────────────────────────────────────────┐
│                    PipelineOrchestrator                       │
│  (state management, cancellation, threading, config reload)  │
└──────────────────────────┬──────────────────────────────────┘
                           │
       ┌───────────────────┼───────────────────┐
       ▼                   ▼                   ▼
┌─────────────┐    ┌─────────────┐    ┌─────────────┐
│  Research   │    │   Scraper   │    │   Idea Gen  │
│  (LLM)      │    │  (HTTP)     │    │  (LLM+JSON) │
└──────┬──────┘    └──────┬──────┘    └──────┬──────┘
       │                  │                  │
       ▼                  ▼                  ▼
┌─────────────────────────────────────────────────────────────┐
│                      Scriptwriter (LLM)                     │
└──────────────────────────┬──────────────────────────────────┘
                           │
       ┌───────────────────┼───────────────────┐
       ▼                   ▼                   ▼
┌─────────────┐    ┌─────────────┐    ┌─────────────┐
│  Voiceover  │    │  Visuals    │    │    Guide    │
│  (Edge/OV)  │    │ (Pexels/SD) │    │  (LLM+HTML) │
└──────┬──────┘    └──────┬──────┘    └──────┬──────┘
       │                  │                  │
       ▼                  ▼                  ▼
┌─────────────┐    ┌─────────────┐    ┌─────────────┐
│ Audio Gen   │    │  Assembly   │    │  Guide      │
│ (Stable     │    │ (FFmpeg)    │    │  Deploy     │
│  Audio 3)   │    │             │    │  (GitHub)   │
└──────┬──────┘    └──────┬──────┘    └──────┬──────┘
       │                  │                  │
       ▼                  ▼                  ▼
┌─────────────┐    ┌─────────────┐    ┌─────────────┐
│   Shorts    │    │  Upload     │    │ Community   │
│  (Scene     │    │ (YouTube)   │    │  Posts      │
│  select)    │    │             │    │             │
└─────────────┘    └─────────────┘    └─────────────┘
```

**All LLM calls route through FreeLLMAPI** → automatic provider failover, penalty tracking, system prompt injection.

---

## Agent Reach Integration (v0.2.0+)

The `ResearchAgent` now leverages **Agent Reach** — a capability layer giving agents unified, zero-API-cost access to internet sources:

| Source | Tool | Method |
|--------|------|--------|
| **YouTube** | `yt-dlp` | Transcript + metadata extraction |
| **Web Articles** | Jina Reader (`curl r.jina.ai/URL`) | Clean article extraction |
| **GitHub** | `gh CLI` | Repo metadata + README |
| **Semantic Search** | `mcporter` + Exa MCP | Neural web search |
| **RSS/Atom** | `feedparser` | Feed parsing |

**No API keys required** for any of the above. The tools are installed as system dependencies (see Installation).

### External Dependencies (install once)

```bash
# Windows (via winget/choco)
winget install GitHub.cli
npm install -g mcporter
mcporter config add exa https://mcp.exa.ai/mcp

# Python deps installed automatically with package
# yt-dlp, feedparser, agent-reach
```

### Research Agent Capabilities

```python
from youtube_factory.agents.research import ResearchAgent

agent = ResearchAgent(config)

# YouTube transcript
result = agent.run({"topic_seed": "https://youtube.com/watch?v=...", "run_dir": "/tmp/run"})

# GitHub repo deep-dive
result = agent.run({"topic_seed": "https://github.com/owner/repo", "run_dir": "/tmp/run"})

# Web article (Jina Reader)
result = agent.run({"topic_seed": "https://anthropic.com/news/...", "run_dir": "/tmp/run"})

# Semantic search (Exa)
# (Triggered automatically for generic queries in future versions)
```

The agent auto-detects the source type from the URL and routes to the appropriate backend.

---

## VoiceoverAgent Capabilities (v0.2.0+)

The `VoiceoverAgent` now supports **Supertonic TTS** — a lightning-fast, on-device, multilingual TTS system running via ONNX Runtime with zero VRAM usage:

| Provider | Model | Hardware | Quality |
|----------|-------|----------|---------|
| **Supertonic (M4)** | 99M params, ONNX Runtime | **CPU only** | 44.1kHz studio quality |
| OmniVoice | Various | GPU | High |
| Edge TTS | Microsoft Neural | CPU | Good |

### Configuration

```json
{
  "voice_provider": "supertonic_http",
  "supertonic": {
    "base_url": "http://127.0.0.1:7788",
    "voice_name": "M4",
    "total_steps": 8,
    "speed": 1.05
  }
}
```

### External Dependency (install once)

```bash
pip install 'supertonic[serve]'
supertonic serve --host 127.0.0.1 --port 7788
```

### Usage

```python
from youtube_factory.agents.voice import VoiceoverAgent

agent = VoiceoverAgent(config)
result = agent.run({
    "script_output": {"script_file": "...", "script_text": "..."},
    "run_dir": "/tmp/run"
})
```

The agent auto-detects `voice_provider: "supertonic_http"` and routes to the local Supertonic server (OpenAI-compatible `/v1/audio/speech` endpoint).

---

## Development

```bash
# Clone
git clone https://github.com/bgill55/youtube-factory-pipeline.git
cd youtube-factory-pipeline

# Install in editable mode with dev deps
pip install -e ".[dev]"

# Run tests
pytest tests/

# Lint
ruff check src/
mypy src/youtube_factory/
```

---

## Related Projects

- **FreeLLMAPI** — The unified LLM router this pipeline depends on
- **OmniVoice-Studio** — Local TTS service
- **YouTube Factory** — Full production deployment (Flask dashboard, scheduler, bootstrap scripts)

---

## License

MIT © 2026 bgill55

---

## Disclaimer

> **This is the orchestration library only.**  
> You must run the required external services yourself:
> - FreeLLMAPI (port 3001)
> - OmniVoice-Studio (port 3900) 
> - Stable Diffusion WebUI --api (port 7860)
> - FFmpeg (system binary)
> 
> See the main [YouTube Factory](https://github.com/bgill55/YouTube_Factory) repo for Docker Compose, bootstrap scripts, and the Flask dashboard.
