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
required
Database instance for publish queue and analytics
Credentials
required
Credentials manager with YouTube API OAuth access
Properties
YouTubeAPI
YouTube Data API v3 client
Array
Queue of scheduled and published content
Logger
Logger instance for tracking publishing operations
Methods
initialize()
Initializes the agent, sets up YouTube API, and loads publish queue.Promise<boolean>
Returns true when initialization is complete
scheduleContent(productionData)
Schedules content for future publishing.Object
required
Production data from ProductionManagementAgent
string
required
Production ID
Object
required
Video script with title
string
required
ISO timestamp for publishing
number
required
Priority score
Object
required
SEO metadata
Object
required
All production assets
Promise<Object>
Schedule entry object
publishContent(contentId)
Publishes content to YouTube immediately.string
required
Production ID or schedule entry ID
Promise<Object>
Updated schedule entry with YouTube ID and URL
string
Updated to ‘published’
string
ISO timestamp of actual publish time
string
YouTube video ID
string
Full YouTube video URL
uploadToYouTube(scheduleEntry)
Uploads video, thumbnail, and captions to YouTube.Object
required
Schedule entry with metadata and assets
Promise<Object>
YouTube API response with video ID
uploadThumbnail(videoId, thumbnailPath)
Uploads custom thumbnail for a video.string
required
YouTube video ID
string
required
Path to thumbnail file
Promise<void>
Completes when upload succeeds
uploadCaptions(videoId, captionsPath)
Uploads SRT captions for a video.string
required
YouTube video ID
string
required
Path to SRT caption file
Promise<void>
Completes when upload succeeds
processPublishQueue()
Processes publish queue and auto-publishes ready content.Promise<number>
Number of videos published
getUpcomingSchedule(days)
Gets upcoming scheduled publications.number
default:"7"
Number of days to look ahead
Promise<Array<Object>>
Array of upcoming schedule entries, sorted by publish time
optimizePublishTimes()
Optimizes scheduled publish times based on channel analytics.Promise<void>
Completes when optimization is done
getChannelAnalytics()
Fetches channel analytics from YouTube.Promise<Object>
Channel analytics data
number
Total channel views
number
Current subscriber count
number
Total video count
Array<string>
Best days to publish
Array<number>
Best hours to publish
createPublishingReport()
Generates comprehensive publishing report.Promise<Object>
Publishing report with statistics and performance
emergencyPublish(contentId, delayMinutes)
Publishes content immediately or with short delay.string
required
Production ID
number
default:"0"
Delay in minutes (0 for immediate)
Promise<Object>
Published or rescheduled entry
pauseScheduledContent(contentId)
Pauses scheduled content.string
required
Production ID
Promise<Object>
Updated entry with status ‘paused’
resumeScheduledContent(contentId, newPublishTime)
Resumes paused content.string
required
Production ID
string
New publish time (ISO string). If not provided, uses existing time.
Promise<Object>
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
string
default:"public"
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.