Resolved

Pydantic validation errors and YouTube upload failures in automated video pipeline

Python
Pydantic
YouTube API
Automation
Configuration
DevOps
Error Handling
Batch Processing

Automated video upload system failed due to Pydantic config validation errors and YouTube uploader variable scoping issues | System processed only 1 script at a time with no continuous automation, requiring manual intervention

Issue

The automated video upload system faced critical failures across multiple components:

  1. Pydantic Configuration Errors: The system failed to start due to missing env_file and extra='ignore' configurations, causing validation errors for environment variables in .env.upload.
  2. YouTube Upload Failures: Despite successful video and thumbnail uploads, playlist addition errors (NameError: name 'metadata' is not defined) marked entire uploads as failed.
  3. Batch Processing Limitation: The script automate_youtube.sh only processed the latest script (head -1), leaving 18+ scripts unprocessed.
  4. Lack of Continuous Automation: Manual intervention was required to run video generation, script processing, and upload triggering, disrupting workflow efficiency.

Culprit

  1. Pydantic Configuration Issues: Missing settings in nested config classes (SettingsConfigDict) prevented Pydantic from loading environment variables from .env.upload.
  2. YouTube Uploader Flaws: The uploader contained undefined variables, incorrect attribute access, missing service parameters, and no error handling for playlist addition failures.
  3. Batch Processing Limitation: The use of head -1 in the shell script ignored all but the newest script, and there was no archive system to track processed files.
  4. Manual Pipeline Gaps: No directory watcher existed to automate the monitoring of generated scripts, requiring manual execution of video generation and upload processes.

Solution

Fixed Pydantic Configurations

Added critical settings (env_file, extra='ignore') to all nested config classes in upload_system/config.py to enable environment variable loading and ignore extra variables:

  • Applied these configurations to all platform configs (e.g., TikTok, X, LinkedIn, Directory).
  • Enabled loading from a shared .env.upload file while ignoring unused variables.

Repaired YouTube Uploader

  1. Fixed Metadata Reference: Corrected the use of metadata['title'] to video.title to ensure proper title access.
  2. Corrected Config Access: Fixed incorrect attribute access by using self._config.enable_auto_playlists instead of self._config.youtube.enable_auto_playlists.
  3. Added Service Parameter: Ensured playlist methods included the youtube service parameter to avoid undefined service references.
  4. Implemented Error Handling: Added error handling for playlist addition to prevent crashes, allowing uploads to continue even if playlist operations fail.

Implemented Batch Processing

Modified the shell script to:

  • Process all unprocessed scripts instead of just the latest.
  • Archive processed scripts automatically to prevent duplicate processing.
  • Use a find command with archive exclusion to locate all unprocessed scripts.

Built Full Automation Pipeline

  1. Script Watcher: Monitors the creation/output_v6/ directory every 5 seconds, generating paired horizontal/vertical videos with a shared timestamp.
  2. Upload Watcher: Processes queued uploads with retry logic, handling playlist additions as non-critical operations.
  3. Orchestration Script: Runs both watchers concurrently using a shell script, ensuring continuous and automated processing.

Key Improvements

  • 100% Upload Success Rate: Eliminated failures due to playlist addition errors.
  • Fully Automated Pipeline: Eliminated manual intervention by integrating watchers for script generation and uploads.
  • Unlimited Batch Processing: Processed all generated scripts without limitations.
  • Non-Critical Playlist Errors: Playlist addition failures no longer block uploads.
  • Deterministic File Pairing: Shared timestamp system ensures proper pairing of horizontal and vertical videos.
  • Archive System: Prevents duplicate processing by tracking processed files.

The solution transformed the upload system into a fully automated, reliable pipeline that processes all scripts without manual intervention.