YouTube Automator is a Python workflow that can generate and upload both YouTube Shorts and long-form educational videos. It picks a topic, writes a script with Gemini, generates voiceover audio, downloads royalty-free visuals and music, renders the final video with MoviePy, and uploads it to YouTube.
This README is written to help someone clone the repository on a new computer and run it successfully from scratch.
The pipeline supports two flows:
- Shorts flow via main.py
- Long-form flow via main_long.py
Typical output files:
final_video.mp4for Shortsfinal_long_video.mp4for long-form videosfinal_long_video.srtfor long-form subtitles
- Topic generation for educational/fact-style content
- AI script generation using Gemini
- Voice generation with
edge-tts, plus fallback togTTSandpyttsx3 - Stock video selection from Pexels and Pixabay
- Music download and background audio support
- Automatic video rendering with MoviePy
- Automatic YouTube upload through the YouTube Data API
- Windows automation helpers via batch files and PowerShell scripts
Before running this project on any PC, make sure you have:
- Python 3.10 or 3.11 installed
- Git installed
- A stable internet connection
- A Google account with access to YouTube uploads
- Your own API credentials for the services you want to use
To run the full project, you should prepare these:
-
Google Gemini API key
- Used for script generation
- Stored in
.envasGEMINI_API_KEYorGEMINI_API_KEYS
-
Pexels API key
- Used for stock video downloads
- Stored in
.envasPEXELS_API_KEY
-
Pixabay API key
- Used as a fallback source for stock videos
- Stored in
.envasPIXABAY_API_KEY
-
YouTube OAuth credentials
- Download your OAuth desktop app credentials JSON from Google Cloud
- Save it in the repository root as
client_secret.json
Windows / macOS / Linux:
git clone https://github.com/shiv989898/Youtube-Automator.git
cd Youtube-AutomatorWindows (PowerShell):
python -m venv .venv
.\.venv\Scripts\Activate.ps1If PowerShell blocks activation, run this once in a PowerShell window:
Set-ExecutionPolicy -Scope CurrentUser RemoteSignedWindows (Command Prompt):
python -m venv .venv
.venv\Scripts\activate.batmacOS / Linux:
python3 -m venv .venv
source .venv/bin/activatepip install --upgrade pip
pip install -r requirements.txtCopy the example file:
Windows (PowerShell):
Copy-Item .env.example .envWindows (Command Prompt):
copy .env.example .envmacOS / Linux:
cp .env.example .envThen edit .env and add your real values.
Example:
GEMINI_API_KEY=your_gemini_key_here
PEXELS_API_KEY=your_pexels_key_here
PIXABAY_API_KEY=your_pixabay_key_here
YOUTUBE_API_KEY=optional_if_neededPlace your Google OAuth desktop app credentials file in the project root as:
client_secret.json
This file is required for uploading videos to YouTube.
On the first successful upload attempt:
- A browser window will open
- You will log in to your Google account
- You will approve YouTube upload access
- The project will save
token.picklelocally for future uploads
You do not need to create token.pickle manually. It is generated automatically.
You can run the project either with Python directly or with the included launcher scripts.
This is the most reliable option on any PC.
python main.pypython main_long.pyOn macOS or Linux, if python does not point to the virtual environment interpreter, use:
python3 main.py
python3 main_long.pyThese now work relative to the repository folder and are safe to use on any Windows PC after setup.
run_shorts.batrun_long.batWhen you run main.py, the project will:
- Pick a topic
- Generate a short script
- Clean the script for narration
- Generate voiceover audio
- Calculate voiceover duration
- Download matching visuals
- Download background music
- Render a Short
- Upload it to YouTube
When you run main_long.py, the project will:
- Pick a topic
- Generate a long-form script
- Clean the script for narration
- Generate voiceover audio
- Calculate voiceover duration
- Download landscape visuals
- Download background music
- Render a long-form video
- Generate subtitles
- Upload it to YouTube
After a successful run, you should typically see files like:
voiceover.mp3voiceover_long.mp3visual_0.mp4,visual_1.mp4, etc.long_visual_0.mp4,long_visual_1.mp4, etc.final_video.mp4final_long_video.mp4final_long_video.srt
git clone https://github.com/shiv989898/Youtube-Automator.git
cd Youtube-Automator
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install --upgrade pip
pip install -r requirements.txt
Copy-Item .env.example .env
notepad .env
# Add your API keys to .env
# Put client_secret.json in the repo root
python main.pygit clone https://github.com/shiv989898/Youtube-Automator.git
cd Youtube-Automator
python -m venv .venv
.venv\Scripts\activate.bat
pip install --upgrade pip
pip install -r requirements.txt
copy .env.example .env
notepad .env
python main.pygit clone https://github.com/shiv989898/Youtube-Automator.git
cd Youtube-Automator
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
cp .env.example .env
nano .env
# Add your API keys
# Put client_secret.json in the repo root
python3 main.pyIf you only want to test generation locally, you can still run the project, but the YouTube step requires valid client_secret.json and successful OAuth login.
If you want a true local-only mode later, that can be added as a feature.
Your virtual environment is probably not activated, or dependencies were not installed.
Fix:
pip install -r requirements.txtRun:
Set-ExecutionPolicy -Scope CurrentUser RemoteSignedMake sure the file exists in the repository root.
Delete token.pickle and rerun the script to trigger a fresh Google login.
The project tries edge-tts first, then gTTS, then pyttsx3 as a fallback.
This is normal for MoviePy, especially on long-form runs.
Check that your API keys are valid and not rate-limited.
- Windows batch launchers: run_shorts.bat, run_long.bat
- Windows looping script:
loop_shorts.ps1 - Task Scheduler setup: see TASK_SCHEDULER_SETUP.md
- Cloud/CI options: EASY_DEPLOYMENT.md, GITHUB_ACTIONS_SETUP.md, FLY_DEPLOYMENT.md, RENDER_DEPLOYMENT.md, RAILWAY_SETUP.md
- main.py: Shorts workflow entry point
- main_long.py: Long-form workflow entry point
- script_generator.py: Shorts script generation
- script_generator_long.py: Long-form script generation
- voiceover.py: Voice generation
- visuals.py: Shorts visual collection
- visuals_long.py: Long-form visual collection
- video_creator.py: Shorts video rendering
- long_video_creator.py: Long-form video rendering
- youtube_uploader.py: Shorts upload
- youtube_uploader_long.py: Long-form upload
Please do not commit:
.envclient_secret.jsontoken.pickle- generated media files
- personal credentials of any kind
This project is licensed under the MIT License. See LICENSE.
You are responsible for complying with the terms of the APIs and content providers you use, including Google, Pexels, Pixabay, Microsoft, and any music or media sources referenced by the project.