Overview
ThePublishingSchedulingAgent manages the complete video publishing workflow to YouTube. It handles scheduling, uploads, metadata optimization, thumbnail uploads, caption uploads, and publishing analytics.
Constructor
Database instance for publish queue and analytics
Credentials manager with YouTube API OAuth access
Properties
YouTube Data API v3 client
Queue of scheduled and published content
Logger instance for tracking publishing operations
Methods
initialize()
Initializes the agent, sets up YouTube API, and loads publish queue.Returns true when initialization is complete
scheduleContent(productionData)
Schedules content for future publishing.Production data from ProductionManagementAgent
Production ID
Video script with title
ISO timestamp for publishing
Priority score
SEO metadata
All production assets
Schedule entry object
publishContent(contentId)
Publishes content to YouTube immediately.Production ID or schedule entry ID
Updated schedule entry with YouTube ID and URL
Updated to ‘published’
ISO timestamp of actual publish time
YouTube video ID
Full YouTube video URL
uploadToYouTube(scheduleEntry)
Uploads video, thumbnail, and captions to YouTube.Schedule entry with metadata and assets
YouTube API response with video ID
uploadThumbnail(videoId, thumbnailPath)
Uploads custom thumbnail for a video.YouTube video ID
Path to thumbnail file
Completes when upload succeeds
uploadCaptions(videoId, captionsPath)
Uploads SRT captions for a video.YouTube video ID
Path to SRT caption file
Completes when upload succeeds
processPublishQueue()
Processes publish queue and auto-publishes ready content.Number of videos published
getUpcomingSchedule(days)
Gets upcoming scheduled publications.Number of days to look ahead
Array of upcoming schedule entries, sorted by publish time
optimizePublishTimes()
Optimizes scheduled publish times based on channel analytics.Completes when optimization is done
getChannelAnalytics()
Fetches channel analytics from YouTube.Channel analytics data
Total channel views
Current subscriber count
Total video count
Best days to publish
Best hours to publish
createPublishingReport()
Generates comprehensive publishing report.Publishing report with statistics and performance
emergencyPublish(contentId, delayMinutes)
Publishes content immediately or with short delay.Production ID
Delay in minutes (0 for immediate)
Published or rescheduled entry
pauseScheduledContent(contentId)
Pauses scheduled content.Production ID
Updated entry with status ‘paused’
resumeScheduledContent(contentId, newPublishTime)
Resumes paused content.Production ID
New publish time (ISO string). If not provided, uses existing time.
Updated entry with status ‘scheduled’
Upload Metadata Structure
YouTube video upload includes:Usage Example
Automated Publishing Workflow
Schedule Content
Schedule Content
Content is added to publish queue with calculated optimal publish time from strategy.
Queue Processing
Queue Processing
Run processPublishQueue() on a cron job (e.g., every 5 minutes) to automatically publish content when time arrives.
Optimization
Optimization
Periodically run optimizePublishTimes() (e.g., weekly) to adjust scheduled times based on analytics.
Monitoring
Monitoring
Use createPublishingReport() to track accuracy, frequency, and identify issues.
Best Practices
Set Up Cron Jobs
Set Up Cron Jobs
Run processPublishQueue() every 5 minutes to ensure timely publishing. Most content publishes within 5 minutes of scheduled time.
Monitor Queue Status
Monitor Queue Status
Check for ‘failed’ status items and retry or investigate issues. Common failures: API rate limits, invalid video files, authentication errors.
Use Privacy Status Wisely
Use Privacy Status Wisely
Default is ‘public’. Use ‘unlisted’ for testing or ‘private’ for scheduled publishing with manual review.
Optimize Publish Times
Optimize Publish Times
Run optimizePublishTimes() weekly to adapt to audience behavior changes.
Emergency Publishing
Emergency Publishing
Use emergencyPublish() for time-sensitive or trending topic videos that need immediate publication.
Environment Variables
Default privacy status for uploads: public, unlisted, or private
YouTube API Requirements
OAuth 2.0 Credentials
OAuth 2.0 Credentials
Requires OAuth 2.0 credentials with YouTube Data API v3 scope: https://www.googleapis.com/auth/youtube.upload
API Quotas
API Quotas
Video uploads cost 1600 quota units. Default quota is 10,000 units per day (6 uploads). Request quota increase for higher volume.
Rate Limits
Rate Limits
YouTube enforces rate limits on uploads. The agent includes error handling for quota exceeded errors.