@openpets/youtube
v1.0.4
Published
A comprehensive YouTube plugin for OpenCode that provides full creator functionality including video uploads, metadata management, analytics, and channel management using the official YouTube Data API.
Downloads
141
Maintainers
Readme
YouTube Plugin for OpenCode
A comprehensive YouTube plugin for OpenCode that provides full creator functionality including video uploads, metadata management, analytics, and channel management using the official YouTube Data API.
Features
- Video Management: Upload, update, and delete videos
- Metadata Control: Update titles, descriptions, tags, categories, and privacy settings
- Channel Analytics: Get detailed analytics and channel statistics
- Search & Filter: List and search through your videos with various filters
- Read-Only Mode: Safe mode for viewing only, no accidental modifications
- OAuth2 Authentication: Secure authentication with refresh token support
Setup
1. Get YouTube API Credentials
- Go to Google Cloud Console
- Create a new project or select an existing one
- Enable the following APIs:
- YouTube Data API v3
- YouTube Analytics API
- Go to Credentials section
- Create API Key for read operations
- Create OAuth 2.0 Client ID for write operations:
- Application type: Web application
- Add authorized redirect URI (e.g.,
http://localhost:3000/callback)
- Note down the Client ID and Client Secret
2. Configure Environment Variables
Create a .env file in your YouTube plugin directory:
# Required - YouTube Data API v3
YOUTUBE_API_KEY=your_youtube_api_key_here
# Required - OAuth2 Credentials
YOUTUBE_CLIENT_ID=your_oauth2_client_id_here
YOUTUBE_CLIENT_SECRET=your_oauth2_client_secret_here
YOUTUBE_REDIRECT_URI=http://localhost:3000/callback
# Optional - For persistent authentication
YOUTUBE_REFRESH_TOKEN=your_refresh_token_here
# Optional - Enable read-only mode
YOUTUBE_READ_ONLY=true3. First-time Authentication
The first time you use write operations, you'll need to complete the OAuth2 flow to get a refresh token. The plugin will guide you through this process.
Usage Examples
Test Connection
opencode run "test youtube connection"List Your Videos
opencode run "list my youtube videos"
opencode run "list my youtube videos with max results 10 and include details"Get Video Details
opencode run "get details for video ID dQw4w9WgXcQ"
opencode run "get video details for dQw4w9WgXcQ with analytics"Upload a Video
opencode run "upload video at /path/to/video.mp4 with title 'My New Video' and description 'Check out my new video!'"Update Video Metadata
opencode run "update video dQw4w9WgXcQ title to 'Updated Title' and privacy to 'public'"Get Channel Information
opencode run "get my youtube channel info with statistics"Get Analytics
opencode run "get analytics for my youtube videos for the last 30 days"
opencode run "get video analytics for video ID dQw4w9WgXcQ"Delete a Video
opencode run "delete youtube video dQw4w9WgXcQ"Read-Only Mode
For safety, you can enable read-only mode to prevent accidental modifications:
export YOUTUBE_READ_ONLY=trueIn read-only mode:
- ✅ List videos
- ✅ Get video details
- ✅ Get channel info
- ✅ Get analytics
- ❌ Upload videos
- ❌ Update metadata
- ❌ Delete videos
Available Tools
Core Tools
youtube-test-connection- Test API connection and authenticationyoutube-upload-video- Upload new videos with metadatayoutube-list-videos- List and filter your videosyoutube-get-video- Get detailed video informationyoutube-update-video- Update video metadatayoutube-delete-video- Delete videos from your channel
Analytics Tools
youtube-get-channel-analytics- Get channel statistics and informationyoutube-get-video-analytics- Get detailed analytics data
Tool Parameters
Video Upload
title(required): Video titledescription(optional): Video descriptiontags(optional): Array of video tagscategoryId(optional, default: "22"): YouTube category IDprivacyStatus(optional, default: "private"): "private", "public", or "unlisted"filePath(required): Local path to video file
Video List & Search
maxResults(optional, default: 25): Maximum videos to return (1-50)status(optional, default: "all"): Filter by privacy statusorder(optional, default: "date"): Sort orderpublishedAfter(optional): Filter by date (ISO format)publishedBefore(optional): Filter by date (ISO format)includeDetails(optional, default: false): Include full video details
Video Category IDs
Common YouTube category IDs:
- 1: Film & Animation
- 2: Autos & Vehicles
- 10: Music
- 15: Pets & Animals
- 17: Sports
- 19: Travel & Events
- 20: Gaming
- 22: People & Blogs (default)
- 23: Comedy
- 24: Entertainment
- 25: News & Politics
- 26: Howto & Style
- 27: Education
- 28: Science & Technology
Rate Limits & Quotas
The YouTube API has daily quotas:
- Standard quota: 10,000 units per day
- Upload operations: ~1,600 units per video
- List operations: ~1-100 units per request
- Analytics queries: ~1-10 units per query
The plugin includes built-in rate limiting to help manage quotas. If you exceed limits, wait for the quota to reset (typically at midnight Pacific Time).
Troubleshooting
"Plugin not configured" Error
Ensure all required environment variables are set:
- YOUTUBE_API_KEY
- YOUTUBE_CLIENT_ID
- YOUTUBE_CLIENT_SECRET
- YOUTUBE_REDIRECT_URI
Authentication Issues
- Verify OAuth2 credentials are correct
- Check redirect URI matches exactly in Google Cloud Console
- Ensure YouTube APIs are enabled in your project
- Try re-authenticating to get a fresh refresh token
Video Upload Fails
- Check video file exists and is accessible
- Ensure video format is supported (MP4 recommended)
- Verify file size is within YouTube limits (max 256GB)
- Check available storage quota in your Google account
API Quota Exceeded
- Wait for daily quota reset (midnight Pacific Time)
- Optimize API calls by batching operations
- Request quota increase in Google Cloud Console if needed
Development
This plugin uses:
- OpenPets SDK: Plugin framework and utilities
- Google APIs Node.js Client: Official YouTube Data API client
- Google Auth Library: OAuth2 authentication
To modify or extend:
- Edit
index.tsto add new tools - Update
package.jsonwith new dependencies - Test with
opencode runcommands - Build with
pets build
Support
For issues related to:
- YouTube API: YouTube API Documentation
- Google Cloud Console: Google Cloud Support
- This Plugin: Check the FAQ in
package.jsonor OpenCode documentation
License
This plugin is part of the OpenPets ecosystem and follows the same license terms.
