An automated tool that analyzes YouTube videos, identifies engaging segments, and creates optimized Shorts content.
- 📥 Downloads YouTube videos
- 🎯 Identifies engaging segments for Shorts
- 🗣️ Transcribes video content
- 🤖 AI-powered content analysis
- ✂️ Automatically creates vertical format clips
- 🇧🇷 Optimized for Brazilian Portuguese content
- Python 3.11+
- OpenAI API Key
- YouTube API Key
youtube-shorts-generator/
├── src/
│ ├── analyzer.py # AI content analysis
│ ├── clipper.py # Video clip creation
│ ├── config.py # Configuration and paths
│ ├── downloader.py # YouTube video download
│ ├── schemas.py # Pydantic models
│ ├── transcriber.py # Audio transcription
│ ├── utils.py # Utility functions
│ └── youtube_client.py # YouTube client
├── data/
│ ├── videos/ # Downloaded videos
│ ├── audio/ # Extracted audio
│ ├── transcripts/ # Video transcriptions
│ ├── analysis/ # Shorts analysis
│ └── clips/ # Generated Shorts
├── main.py # Main execution script
└── README.md
Create a .env
file in the root directory with the following options:
# Required API Keys
OPENAI_API_KEY=your_openai_api_key_here
YOUTUBE_API_KEY=your_youtube_api_key_here
# YouTube Search Parameters (optional, showing defaults)
MAX_RESULTS=2 # Number of videos to process
REGION_CODE=US # Country code for video search
SEARCH_DAYS=1 # Days to look back for videos
RELEVANCE_LANGUAGE=en # Language for content (possible values: 'en' or 'pt')
SEARCH_QUERY= # Optional search query (e.g., "trending tech")
MIN_VIEW_COUNT=1000 # Minimum view count for video processing
# Video Processing Parameters (optional, showing defaults)
MAX_VIDEO_DURATION=1200 # Maximum source video duration (20 minutes)
MIN_VIDEO_DURATION=120 # Minimum source video duration (2 minutes)
# Shorts/Clips Parameters (optional, showing defaults)
MAX_CLIP_DURATION=60 # Maximum clip duration
MIN_CLIP_DURATION=15 # Minimum clip duration
MAX_CLIPS_PER_VIDEO=5 # Maximum clips per video
The tool supports two languages and validates content accordingly:
en
: English (default)- Validates that video titles are in English
- Generates English titles and tags
- Transcribes content in English
pt
: Brazilian Portuguese- Validates that video titles are in Portuguese
- Generates Brazilian Portuguese titles and tags
- Transcribes content in Portuguese
Videos with titles in different languages than specified in RELEVANCE_LANGUAGE
will be automatically filtered out.
Set your preferred language using the RELEVANCE_LANGUAGE
parameter in the .env
file. If an invalid language is provided, the tool will default to English.
The application will:
- Fetch videos based on region (default: US) and language (default: en)
- Filter by optional search query if provided
- Process videos between 2-20 minutes in length
- Process videos from the specified time range
- Create clips between 15-60 seconds
- Generate up to 5 clips per video
- Download: Downloads YouTube videos using yt-dlp
- Transcribe: Uses Whisper to transcribe audio content
- Analyze: Uses OpenAI GPT to identify engaging segments
- Generate: Creates vertical format clips optimized for Shorts
-
Video Download
- Downloads video in best quality
- Extracts audio for transcription
-
Transcription
- Transcribes audio using Whisper
- Saves timestamped transcription
-
Content Analysis
- Analyzes transcription for engaging segments
- Identifies 3-5 potential Shorts clips
- Generates Portuguese titles and tags
-
Clip Generation
- Creates vertical format (9:16)
- Adds blurred background when needed
- Optimizes for Shorts format
- Names clips using suggested titles
- Clone the repository:
git clone https://github.com/yourusername/youtube-shorts-generator.git
cd youtube-shorts-generator
- Install dependencies:
pip install -r requirements.txt
-
Set up your environment variables in
.env
-
Run the generator:
python main.py
The tool will:
- Fetch yesterday's top videos from YouTube
- Download each video
- Generate transcriptions
- Analyze content for potential Shorts
- Create vertical format clips
- Save processing results in JSON format
The tool generates a daily results file (results_YYYY-MM-DD.json
) containing:
- Processing metadata (date, region, video counts)
- For each video:
- Basic information (title, ID, publish date)
- Transcription details
- Analysis results
- Generated clips information
- Processing status
All generated files are organized in the data/
directory:
video/
: Original downloaded videosaudio/
: Extracted audio filestranscripts/
: Video transcriptionsanalysis/
: AI analysis resultsclips/
: Generated Shorts clips
The tool generates:
- Transcription files (JSON)
- Analysis reports (JSON)
- Vertical format clips ready for Shorts
- Processing status logs
- Resolution: 1080x1920 (9:16)
- Format: MP4 with H.264 encoding
- Duration: < 60 seconds
- Filename: Based on generated Portuguese title
The tool includes error handling for:
- Download failures
- Transcription errors
- Analysis failures
- Video processing issues
- File system operations
Feel free to:
- Open issues
- Submit PRs
- Suggest improvements
- Report bugs
MIT License