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.
- 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
- 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)
- 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
- Raspberry Pi 4 (4GB+ RAM recommended)
- 32GB+ microSD card
- Stable internet connection
- Ubuntu 24 or Raspberry Pi OS
- Python 3.8+
- FFmpeg
- Git
- OpenAI API key (for TTS, Whisper, GPT-4)
- YouTube Data API v3 credentials (OAuth 2.0)
# Clone the repository
git clone https://github.com/nicksimpkins/shortsmachine-v2c.git
cd shortsmachine
# Run automated setup
chmod +x setup.sh
./setup.shThe setup script will:
- Install system dependencies (Python, FFmpeg, etc.)
- Create Python virtual environment
- Install Python packages
- Create necessary directories
- Install systemd services
- Run system tests
# 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- Go to Google Cloud Console
- Create a new project
- Enable YouTube Data API v3
- Create OAuth 2.0 credentials
- Download
client_secrets.jsonto project directory
Edit config.py:
OPENAI_API_KEY = "sk-your-api-key-here"Or set environment variable:
export OPENAI_API_KEY="sk-your-api-key-here"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 repostAdd 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# 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 newspython3 main.py --list-types# 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# Live service logs
sudo journalctl -u youtube-shorts-automation.service -f
# Application logs
tail -f logs/automation_*.log# 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.serviceshortsmachine-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
Run comprehensive diagnostics:
python3 test_system.pyThis checks:
- β Python package installation
- β Directory structure
- β FFmpeg availability
- β LLM connectivity (OpenAI/Ollama)
- β YouTube credentials
- β Wikipedia API access
- 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)
- Duration: ~60 seconds
- Sources: BBC, CNN, Guardian RSS feeds
- Features: GPT-4 summarization, professional narration
- Cost: ~$0.10 per video (GPT-4 + TTS + Whisper)
- Duration: ~30 seconds
- Features: Educational content, article images, GPT-4/Ollama extraction
- Cost: ~$0.05 per video (if using OpenAI)
- 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)
- Sources: Popular YouTube Shorts channels
- Minimum Views: 1M+ (configurable)
- Features: Automatic download and re-upload
- Cost: $0 (no AI processing)
- Mix Content Types: Use weighted random mode for variety
- Monitor Performance: Track which content types perform best
- Adjust Thresholds: Lower view requirements if struggling to find content
- Schedule Wisely: Upload during peak hours for your audience
- Storage: Keep cleanup settings aggressive on Pi
- Processing: Avoid running multiple generators simultaneously
- Network: Ensure stable connection for downloads/uploads
- Temperature: Monitor Pi temperature during video encoding
- Backgrounds: Use high-quality 1080x1920 videos
- Audio: 192kbps AAC recommended
- Encoding:
crf=18-23for best quality/size balance - Captions: Ensure good contrast with background
# Update yt-dlp
pip install --upgrade yt-dlp
# Clear cookies (if using authentication)
rm -f ~/.cache/yt-dlp/cookies.txt# 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"# 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# 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# Check memory usage
free -h
# Monitor during encoding
watch -n 1 free -h
# Reduce parallel processing in config
# Lower video bitrates/quality if needed- 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
- 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)
- 720 videos/month
- Mixed content: ~$30-40/month
- Clips/Reposts only: ~$0-5/month
- 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
Contributions welcome! Areas for improvement:
- Additional content generators
- Better segment detection algorithms
- Performance optimizations
- Multi-language support
- Advanced caption styling
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
Technologies Used:
- yt-dlp - YouTube download
- MoviePy - Video editing
- OpenAI - TTS, Whisper, GPT-4
- FFmpeg - Video encoding
- Google YouTube API - Upload automation
For issues and questions:
- Check existing logs in
logs/directory - Run
python3 test_system.pyfor diagnostics - Review configuration in
config.py - Open an issue with full error logs