Uploading YouTube Shorts manually eats up time. Automate your workflow with Python and the YouTube API to schedule uploads, add metadata, and track performance programmatically.
Prerequisites
- Python 3.8+
- Google Account with YouTube Channel
- Installed libraries:
pip install google-auth google-auth-oauthlib google-auth-httplib2 google-api-python-client
Step 1: Enable YouTube API v3
- Go to Google Cloud Console
- Create a new project > Enable YouTube Data API v3
- Under Credentials, create an OAuth 2.0 Client ID
- Download
credentials.jsonfile
Step 2: Authenticate Your Script
Create auth.py to handle OAuth:
from google_auth_oauthlib.flow import InstalledAppFlow
import pickle
scopes = ["https://www.googleapis.com/auth/youtube.upload"]
flow = InstalledAppFlow.from_client_secrets_file("credentials.json", scopes)
credentials = flow.run_console()
pickle.dump(credentials, open("token.pkl", "wb"))
Step 3: Create Upload Script
Build upload_shorts.py:
from googleapiclient.http import MediaFileUpload
from googleapiclient.discovery import build
import pickle
# Load credentials
credentials = pickle.load(open("token.pkl", "rb"))
youtube = build("youtube", "v3", credentials=credentials)
# Upload function
def upload_short(video_path, title, description, tags):
request = youtube.videos().insert(
part="snippet,status",
body={
"snippet": {
"title": title,
"description": description,
"tags": tags,
"categoryId": "22", # Shorts category
"defaultLanguage": "en"
},
"status": {
"privacyStatus": "public", # Or "private"/"unlisted"
"selfDeclaredMadeForKids": False
}
},
media_body=MediaFileUpload(video_path)
)
response = request.execute()
return response
# Example usage
upload_short(
video_path="short1.mp4",
title="My Automated Short #1",
description="Created with Python automation",
tags=["Shorts", "Python", "Automation"]
)
Step 4: Schedule Uploads
Use cron jobs (Linux/macOS) or Task Scheduler (Windows):
# Linux cron example (runs daily at 8 AM)
0 8 * * * /usr/bin/python3 /path/to/upload_shorts.py
Advanced Features
Batch Processing
import os
video_folder = "/path/to/shorts"
for video in os.listdir(video_folder):
if video.endswith(".mp4"):
upload_short(
video_path=os.path.join(video_folder, video),
title=f"Short: {video}",
description="Automated upload",
tags=["Automation"]
)
Error Handling
try:
response = request.execute()
except Exception as e:
print(f"Upload failed: {e}")
# Add retry logic or notifications here
API Quota Management
- Monitor usage at API Dashboard
- Apply for higher quota for bulk uploads
Limitations
- 10,000 API units/day free quota (≈50 uploads)
- No direct Shorts-specific API parameters – use standard video upload with vertical format
Upgrade Options
- Use yt-dlp for video preprocessing
- Integrate with Google Sheets for metadata management
FAQ
Can I monetize automated Shorts?
Yes, but ensure compliance with YouTube’s Terms of Service.
How to add captions programmatically?
Use the captions.insert API endpoint with SRT/WEBVTT files.
Does this work with YouTube Analytics?
Yes – extend the script with the youtubeAnalytics.reports.query endpoint.
Need help customizing the script for your channel? Ask in the comments!
