Module match_command

Module match_command 

Source
Expand description

AI-powered subtitle file matching command implementation.

This module implements the core matching functionality that uses artificial intelligence to analyze video and subtitle files, determine their correspondence, and generate appropriate renamed subtitle files. It supports both dry-run preview mode and actual file operations with comprehensive error handling and progress tracking.

§Matching Algorithm

The AI matching process involves several sophisticated steps:

  1. File Discovery: Scan directories for video and subtitle files
  2. Content Analysis: Extract text samples from subtitle files
  3. AI Processing: Send content to AI service for analysis and matching
  4. Confidence Scoring: Evaluate match quality with confidence percentages
  5. Name Generation: Create appropriate file names based on video files
  6. Operation Planning: Prepare file operations (rename, backup, etc.)
  7. Execution: Apply changes or save for later in dry-run mode

§AI Integration

The matching system integrates with multiple AI providers:

  • OpenAI: GPT-4 and GPT-3.5 models for high-quality analysis
  • Anthropic: Claude models for detailed content understanding
  • Local Models: Self-hosted solutions for privacy-sensitive environments
  • Custom Providers: Extensible architecture for additional services

§Performance Features

  • Parallel Processing: Multiple files processed simultaneously
  • Intelligent Caching: AI results cached to avoid redundant API calls
  • Progress Tracking: Real-time progress indicators for batch operations
  • Error Recovery: Robust error handling with partial completion support
  • Resource Management: Automatic rate limiting and resource optimization

§Safety and Reliability

  • Dry-run Mode: Preview operations before applying changes
  • Automatic Backups: Original files preserved during operations
  • Rollback Support: Ability to undo operations if needed
  • Validation: Comprehensive checks before file modifications
  • Atomic Operations: All-or-nothing approach for batch operations

§Examples

use subx_cli::commands::match_command;
use subx_cli::cli::MatchArgs;
use std::path::PathBuf;

// Basic matching operation
let args = MatchArgs {
    path: PathBuf::from("/path/to/media"),
    recursive: true,
    dry_run: false,
    confidence: 80,
    backup: true,
};

// Execute matching
match_command::execute(args).await?;

Functions§

execute
Execute the AI-powered subtitle matching operation with full workflow.
execute_parallel_match
Execute parallel matching operations across multiple files and directories.
execute_with_client
Execute the matching workflow with dependency-injected AI client.
execute_with_config
Execute the AI-powered subtitle matching operation with injected configuration service.