Skip to content

An automated content creation and upload system for YouTube Shorts, running on Raspberry Pi or other server. Generates engaging short-form videos from multiple content sources including Reddit stories, news articles, Wikipedia facts, trending video clips, and viral shorts reposts.

Notifications You must be signed in to change notification settings

nicksimpkins/shortsmachine-v2c

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Shortsmachine V2 Community

An automated content creation and upload system for YouTube Shorts, running on Raspberry Pi. Generates engaging short-form videos from multiple content sources including Reddit stories, news articles, Wikipedia facts, trending video clips, and viral shorts reposts.

🎬 Features

Content Generation

  • Reddit Stories: Narrated stories from r/nosleep, r/AITAH, and other subreddits with synchronized captions
  • Breaking News: AI-summarized news articles with professional narration
  • Wikipedia Facts: Educational content with fun facts and images
  • Inspirational Quotes: Beautiful quote overlays with scenic backgrounds
  • Trending Clips: Smart extraction of viral moments from YouTube videos using hybrid AI approach
  • Viral Reposts: Automatic reposting of high-performing YouTube Shorts

Advanced Video Creation

  • Professional TTS: OpenAI text-to-speech with multiple voice options
  • Word-Level Captions: Synchronized subtitles using Whisper transcription
  • Smart Cropping: Face detection for intelligent video framing
  • Quality Optimization: FFmpeg-enhanced encoding for maximum YouTube quality
  • Dynamic Backgrounds: Random background video/audio selection
  • Variable Playback Speed: Configurable speed multipliers (1.0x - 1.25x)

Automation

  • Systemd Integration: Runs as a service with automatic scheduling
  • Auto-Updates: Daily git pulls to keep code current
  • Smart Cleanup: Automatic file management to prevent storage overflow
  • Error Recovery: Robust retry logic and fallback mechanisms
  • Resource Management: Optimized for Raspberry Pi 4 constraints

πŸ“‹ Requirements

Hardware

  • Raspberry Pi 4 (4GB+ RAM recommended)
  • 32GB+ microSD card
  • Stable internet connection

Software

  • Ubuntu 24 or Raspberry Pi OS
  • Python 3.8+
  • FFmpeg
  • Git

API Keys

  • OpenAI API key (for TTS, Whisper, GPT-4)
  • YouTube Data API v3 credentials (OAuth 2.0)

πŸš€ Installation

Quick Setup

# Clone the repository
git clone https://github.com/nicksimpkins/shortsmachine-v2c.git
cd shortsmachine

# Run automated setup
chmod +x setup.sh
./setup.sh

The setup script will:

  1. Install system dependencies (Python, FFmpeg, etc.)
  2. Create Python virtual environment
  3. Install Python packages
  4. Create necessary directories
  5. Install systemd services
  6. Run system tests

Manual Setup

# 1. Install system dependencies
sudo apt update
sudo apt install -y python3 python3-venv python3-pip ffmpeg git \
    libjpeg-dev zlib1g-dev

# 2. Install Deno (for enhanced YouTube access)
curl -fsSL https://deno.land/install.sh | sh
export DENO_INSTALL="/home/$(whoami)/.deno"
export PATH="$DENO_INSTALL/bin:$PATH"

# 3. Create virtual environment
python3 -m venv venv
source venv/bin/activate

# 4. Install Python dependencies
pip install -r requirements.txt

# 5. Create directories
mkdir -p temp output backgrounds/video backgrounds/audio logs

# 6. Install systemd services
sudo cp youtube-shorts-automation.service /etc/systemd/system/
sudo cp youtube-shorts-automation.timer /etc/systemd/system/
sudo cp youtube-shorts-git-update.service /etc/systemd/system/
sudo cp youtube-shorts-git-update.timer /etc/systemd/system/
sudo systemctl daemon-reload

βš™οΈ Configuration

1. YouTube API Setup

  1. Go to Google Cloud Console
  2. Create a new project
  3. Enable YouTube Data API v3
  4. Create OAuth 2.0 credentials
  5. Download client_secrets.json to project directory

2. OpenAI API Key

Edit config.py:

OPENAI_API_KEY = "sk-your-api-key-here"

Or set environment variable:

export OPENAI_API_KEY="sk-your-api-key-here"

3. Content Configuration

Edit config.py to customize:

# Select content types
CONTENT_TYPES = ["repost", "clips", "reddit", "news", "fun_fact", "quote"]
CONTENT_MODE = "random"  # or "sequential"

# Set content weights for random mode
CONTENT_WEIGHTS = {
    "repost": 50,
    "clips": 30,
    "reddit": 10,
    "news": 5,
    "fun_fact": 3,
    "quote": 2
}

# Configure upload schedule
UPLOAD_INTERVAL_HOURS = 1  # Upload every N hours

# Content-specific settings
REDDIT_MAX_CHARS = 1710  # ~2 minutes of narration
REDDIT_PLAYBACK_SPEED = 1.25  # Speed up playback

NEWS_MAX_CHARS = 850  # ~60 seconds
CLIPS_MIN_VIEWS = 25_000  # Minimum views for clip source
REPOST_MIN_VIEWS = 100_000  # Minimum views for repost

4. Background Media

Add your background videos and audio:

# Background videos (poker-background.mp4 is default)
cp your-video.mp4 backgrounds/video/

# Background audio (backgroundaudio1.m4a is default)
cp your-audio.m4a backgrounds/audio/

Enable random selection:

RANDOMIZE_BACKGROUNDS = True

🎯 Usage

Test Run

# Activate virtual environment
source venv/bin/activate

# Test with single video
python3 main.py once

# Test specific content type
python3 main.py once --type reddit
python3 main.py once --type clips
python3 main.py once --type news

List Available Content Types

python3 main.py --list-types

Start Automation Service

# Enable and start the timer
sudo systemctl enable youtube-shorts-automation.timer
sudo systemctl start youtube-shorts-automation.timer

# Check status
systemctl list-timers
sudo systemctl status youtube-shorts-automation.timer

Monitor Logs

# Live service logs
sudo journalctl -u youtube-shorts-automation.service -f

# Application logs
tail -f logs/automation_*.log

Manual Control

# Stop automation
sudo systemctl stop youtube-shorts-automation.timer

# Start automation
sudo systemctl start youtube-shorts-automation.timer

# Restart service
sudo systemctl restart youtube-shorts-automation.service

# Run one-time upload
sudo systemctl start youtube-shorts-automation.service

πŸ“ Project Structure

shortsmachine-v2c/
β”œβ”€β”€ main.py                          # Main orchestration
β”œβ”€β”€ config.py                        # Configuration settings
β”œβ”€β”€ setup.sh                         # Automated setup script
β”œβ”€β”€ requirements.txt                 # Python dependencies
β”‚
β”œβ”€β”€ content_generators/              # Content generation modules
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ base_generator.py           # Abstract base class
β”‚   β”œβ”€β”€ registry.py                 # Generator registry
β”‚   β”œβ”€β”€ reddit_generator.py         # Reddit stories
β”‚   β”œβ”€β”€ news_generator.py           # Breaking news
β”‚   β”œβ”€β”€ fun_fact_generator.py       # Wikipedia facts
β”‚   β”œβ”€β”€ quote_generator.py          # Inspirational quotes
β”‚   β”œβ”€β”€ clips_generator.py          # Trending video clips
β”‚   └── repost_generator.py         # Viral shorts reposts
β”‚
β”œβ”€β”€ video_creator.py                 # Video composition engine
β”œβ”€β”€ youtube_uploader.py              # YouTube API integration
β”œβ”€β”€ cleanup_manager.py               # File cleanup utilities
β”œβ”€β”€ wikipedia_scraper.py             # Wikipedia content fetcher
β”œβ”€β”€ llm_extractor.py                # LLM integration (OpenAI/Ollama)
β”‚
β”œβ”€β”€ test_system.py                   # System diagnostics
β”œβ”€β”€ test_ollama.py                   # LLM testing
β”‚
β”œβ”€β”€ youtube-shorts-automation.service    # Systemd service
β”œβ”€β”€ youtube-shorts-automation.timer      # Upload scheduler
β”œβ”€β”€ youtube-shorts-git-update.service    # Auto-update service
β”œβ”€β”€ youtube-shorts-git-update.timer      # Update scheduler
β”‚
β”œβ”€β”€ backgrounds/                     # Media assets
β”‚   β”œβ”€β”€ video/                      # Background videos
β”‚   └── audio/                      # Background music
β”‚
β”œβ”€β”€ temp/                           # Temporary files
β”œβ”€β”€ output/                         # Generated videos
└── logs/                           # Application logs

πŸ”§ System Tests

Run comprehensive diagnostics:

python3 test_system.py

This checks:

  • βœ“ Python package installation
  • βœ“ Directory structure
  • βœ“ FFmpeg availability
  • βœ“ LLM connectivity (OpenAI/Ollama)
  • βœ“ YouTube credentials
  • βœ“ Wikipedia API access

πŸ“Š Content Types Deep Dive

Reddit Stories

  • Duration: 30-180 seconds (configurable)
  • Subreddits: nosleep, AITAH, ScaryStories, etc.
  • Features: TTS narration, word-synced captions, dramatic pacing
  • Cost: ~$0.05 per video (OpenAI TTS + Whisper)

News Articles

  • Duration: ~60 seconds
  • Sources: BBC, CNN, Guardian RSS feeds
  • Features: GPT-4 summarization, professional narration
  • Cost: ~$0.10 per video (GPT-4 + TTS + Whisper)

Wikipedia Facts

  • Duration: ~30 seconds
  • Features: Educational content, article images, GPT-4/Ollama extraction
  • Cost: ~$0.05 per video (if using OpenAI)

Trending Clips

  • Duration: 45 seconds (configurable)
  • Approach: Hybrid - Most Replayed data + GPT-4 validation
  • Features: Smart segment selection, face detection cropping
  • Cost: ~$0.001 per video (GPT-4 validation optional)

Viral Reposts

  • Sources: Popular YouTube Shorts channels
  • Minimum Views: 1M+ (configurable)
  • Features: Automatic download and re-upload
  • Cost: $0 (no AI processing)

πŸ’‘ Tips & Best Practices

Content Strategy

  1. Mix Content Types: Use weighted random mode for variety
  2. Monitor Performance: Track which content types perform best
  3. Adjust Thresholds: Lower view requirements if struggling to find content
  4. Schedule Wisely: Upload during peak hours for your audience

Resource Management

  1. Storage: Keep cleanup settings aggressive on Pi
  2. Processing: Avoid running multiple generators simultaneously
  3. Network: Ensure stable connection for downloads/uploads
  4. Temperature: Monitor Pi temperature during video encoding

Quality Optimization

  1. Backgrounds: Use high-quality 1080x1920 videos
  2. Audio: 192kbps AAC recommended
  3. Encoding: crf=18-23 for best quality/size balance
  4. Captions: Ensure good contrast with background

πŸ› Troubleshooting

YouTube Blocking Downloads

# Update yt-dlp
pip install --upgrade yt-dlp

# Clear cookies (if using authentication)
rm -f ~/.cache/yt-dlp/cookies.txt

OpenAI API Errors

# Check API key
python3 -c "import config; print(config.OPENAI_API_KEY[:8])"

# Test connection
curl https://api.openai.com/v1/models \
  -H "Authorization: Bearer $OPENAI_API_KEY"

Service Won't Start

# Check service status
sudo systemctl status youtube-shorts-automation.service

# View recent logs
sudo journalctl -u youtube-shorts-automation.service -n 50

# Check permissions
ls -la /home/shortsmachine/shortsmachine-v2c

# Verify paths in service file
cat /etc/systemd/system/youtube-shorts-automation.service

FFmpeg Encoding Errors

# Verify FFmpeg installation
ffmpeg -version

# Test encoding
ffmpeg -i input.mp4 -c:v libx264 -crf 23 test_output.mp4

# Check available codecs
ffmpeg -codecs | grep h264

Memory Issues on Pi

# Check memory usage
free -h

# Monitor during encoding
watch -n 1 free -h

# Reduce parallel processing in config
# Lower video bitrates/quality if needed

πŸ“ˆ Performance & Costs

Raspberry Pi 4 Performance

  • Video Generation: 2-5 minutes per video
  • Upload Speed: Depends on internet (usually 1-2 min)
  • Total Cycle: ~5-10 minutes per video
  • Concurrent Limit: 1 video at a time recommended

API Costs (Approximate)

  • Reddit Story: $0.05 (TTS + Whisper)
  • News Article: $0.10 (GPT-4 + TTS + Whisper)
  • Wikipedia Fact: $0.05 (GPT-4-mini + TTS + Whisper)
  • Trending Clip: $0.001 (Optional GPT-4 validation)
  • Viral Repost: $0 (No AI processing)

Monthly Estimates (1 upload/hour)

  • 720 videos/month
  • Mixed content: ~$30-40/month
  • Clips/Reposts only: ~$0-5/month

πŸ”’ Security & Privacy

  • API Keys: Never commit to Git (use environment variables)
  • OAuth Tokens: Stored locally in token.pickle
  • Temporary Files: Automatically cleaned after upload
  • Source Attribution: Metadata includes original sources
  • Content Rights: Ensure compliance with copyright and fair use

🀝 Contributing

Contributions welcome! Areas for improvement:

  • Additional content generators
  • Better segment detection algorithms
  • Performance optimizations
  • Multi-language support
  • Advanced caption styling

πŸ“ License

This project is for educational purposes. Ensure compliance with:

  • YouTube Terms of Service
  • OpenAI Usage Policies
  • Content creator rights and licensing
  • Copyright and fair use laws

πŸ™ Credits

Technologies Used:

πŸ“ž Support

For issues and questions:

  1. Check existing logs in logs/ directory
  2. Run python3 test_system.py for diagnostics
  3. Review configuration in config.py
  4. Open an issue with full error logs

About

An automated content creation and upload system for YouTube Shorts, running on Raspberry Pi or other server. Generates engaging short-form videos from multiple content sources including Reddit stories, news articles, Wikipedia facts, trending video clips, and viral shorts reposts.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published