A Python-based video scheduling system used the YouTube Data API to automate upload timing and prevent collisions. However, the system failed to detect existing scheduled videos and enforced incorrect spacing intervals, leading to missed videos and overlapping upload times.
Issue
The YouTube video scheduler exhibited critical failures:
- Missed scheduled videos: Returned empty results for existing scheduled videos despite their presence.
- Incorrect spacing: Enforced a hardcoded 24-hour interval between uploads, ignoring the configured 6-hour minimum.
- Time slot collisions: New uploads ignored existing schedules, causing overlapping time slots.
- Series handling failure: Multi-part videos were hardcoded to 1-day spacing regardless of configuration.
Culprit
The root causes included:
- Incorrect API usage: The system used an API endpoint (
search().comst()) that excludes private and scheduled videos, resulting in empty results. - Hardcoded spacing: Series videos were enforced to a fixed 24-hour interval, disregarding configuration settings.
- Missing pagination: Only fetched the first 50 videos without handling pagination for channels with more content.
Solution
Updated API Implementation
- Playlist-based approach: Used the YouTube uploads playlist to fetch all scheduled videos, including private and scheduled content.
- Paginated requests: Implemented pagination to handle channels with more than 50 videos.
- Batch processing: Processed video status in batches for efficiency.
Configuration-Driven Spacing
- Dynamic spacing: Modified series scheduling to respect configuration values for spacing between uploads.
- Config compliance: Ensured the system enforced the configured minimum hours between videos.
Synchronization Logic
- Data merging: Added synchronization between API data and in-memory reservations to ensure accurate scheduling.
Results
- Before: Missed scheduled videos and incorrect spacing led to collisions.
- After: All scheduled videos detected, and spacing enforced according to configuration.
This solution ensures accurate video scheduling and proper compliance with YouTube API constraints and configuration settings.