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:
- File Discovery: Scan directories for video and subtitle files
- Content Analysis: Extract text samples from subtitle files
- AI Processing: Send content to AI service for analysis and matching
- Confidence Scoring: Evaluate match quality with confidence percentages
- Name Generation: Create appropriate file names based on video files
- Operation Planning: Prepare file operations (rename, backup, etc.)
- 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.