An automated system that processes YouTube videos and creates viral tweets using AI agents. This project extracts video transcripts, generates engaging tweet content, and automatically posts them to Twitter.
Follow along with the detailed blog post: Automate Tweets from YouTube Videos
- YouTube Transcript Extraction: Automatically fetches video transcripts from YouTube videos
- AI-Powered Tweet Generation: Uses Gemini AI to create viral, engaging tweets from video content
- Automatic Twitter Posting: Posts generated tweets directly to your Twitter account
- Multi-Agent System: Coordinated workflow between Marketing Agent and Twitter Posting Agent
- Error Handling: Robust error handling for API calls and network issues
- Python 3.10+
- OpenAI Agents: Multi-agent framework for coordinated AI workflows
- Tweepy: Twitter API integration
- YouTube Transcript API: For extracting video transcripts
- Gemini AI: For content generation
- Python-dotenv: Environment variable management
Before running this project, make sure you have:
- Python 3.10 or higher installed
- Twitter Developer Account with API keys
- Google AI Studio Account for Gemini API access
- UV package manager (recommended) or pip
- Clone the repository:
https://github.com/HeetVekariya/Youtube-Tweet.git
cd YouTube-Tweet- Install dependencies using UV:
uv syncOr using pip:
pip install -r requirements.txt- Set up environment variables:
cp .env.example .env- Fill in your API credentials in the
.envfile:
GEMINI_API_KEY=your_gemini_api_key
TWITTER_BEARER_TOKEN=your_twitter_bearer_token
TWITTER_CONSUMER_KEY=your_twitter_consumer_key
TWITTER_CONSUMER_SECRET=your_twitter_consumer_secret
TWITTER_API_SECRET=your_twitter_api_secret
TWITTER_ACCESS_TOKEN=your_twitter_access_token
TWITTER_ACCESS_TOKEN_SECRET=your_twitter_access_token_secretRun the script with the default video:
python main.pyYou can modify the DEFAULT_VIDEO_LINK variable in main.py or pass a custom URL programmatically.
- Video Processing: The Marketing Agent fetches the YouTube video transcript
- Content Generation: AI analyzes the transcript and creates an engaging tweet (under 280 characters)
- Tweet Posting: The Twitter Posting Agent handles the actual posting to your Twitter account
- Verification: The system confirms successful posting and provides feedback
YouTube-Tweet/
├── main.py # Main application logic
├── test.py # Test file
├── pyproject.toml # Project configuration
├── .env.example # Environment variables template
├── .env # Your API credentials (not tracked)
├── uv.lock # UV lock file
└── README.md # This file
- Go to Twitter Developer Portal
- Create a new app
- Generate your API keys and tokens
- Add them to your
.envfile
- Visit Google AI Studio
- Create a new project
- Generate an API key
- Add it to your
.envfile
The system uses a coordinated multi-agent approach:
-
Marketing Agent:
- Fetches YouTube video transcripts
- Analyzes content for viral potential
- Creates engaging tweet content
- Hands off to Twitter Posting Agent
-
Twitter Posting Agent:
- Receives tweet content from Marketing Agent
- Posts the tweet to Twitter
- Confirms successful posting
The system includes comprehensive error handling for:
- Invalid YouTube URLs
- API rate limits
- Network connectivity issues
- Missing or invalid API credentials
- Tweet posting failures
Processing video: https://www.youtube.com/watch?v=example
Starting agent workflow...
YouTube summary function called with args: {'video_url': 'https://www.youtube.com/watch?v=example'}
Fetching transcript for: https://www.youtube.com/watch?v=example
Transcript fetched successfully! Length: 5240 characters
Tweet function called with args: {'tweet': 'Your generated tweet content here'}
Tweet posted successfully! ID: 1234567890
✅ Tweet was posted successfully!
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
- OpenAI Agents framework for multi-agent coordination
- YouTube Transcript API for video content extraction
- Tweepy for Twitter integration
- Google's Gemini AI for content generation
For detailed implementation guide and tutorials, check out the blog post.