feat: add tests

This commit is contained in:
CDN 2025-04-23 16:30:45 +08:00
parent 44c7e9bee5
commit bb87f058f0
Signed by: CDN
GPG key ID: 0C656827F9F80080
17 changed files with 4436 additions and 80 deletions

View file

@ -114,15 +114,18 @@ Currently, synchronization only works between files of the same format:
#### For LRC Files:
- **When entry counts match**: The source timeline is directly applied to the target content.
- **When entry counts differ**: The source timeline is scaled to match the target content using linear interpolation.
- **When entry counts differ**: The source timeline is scaled to match the target content using linear interpolation:
- For each target entry position, a corresponding position in the source timeline is calculated
- Times are linearly interpolated between the nearest source entries
- This ensures smooth and proportional timing across entries of different counts
- **Preserved from target**: All content text and metadata (artist, title, etc.).
- **Modified in target**: Only timestamps are updated.
#### For SRT Files:
- **When entry counts match**: Both start and end times from the source are directly applied to the target entries.
- **When entry counts differ**: A scaled approach is used:
- Start times are taken from proportionally matched source entries
- **When entry counts differ**: A scaled approach using linear interpolation is used:
- Start times are calculated using linear interpolation between the nearest source entries
- End times are calculated based on source entry durations
- The timing relationship between entries is preserved
- **Preserved from target**: All subtitle text content.
@ -131,17 +134,35 @@ Currently, synchronization only works between files of the same format:
#### For VTT Files:
- **When entry counts match**: Both start and end times from the source are directly applied to the target entries.
- **When entry counts differ**: A scaled approach is used, similar to SRT synchronization:
- Start times are taken from proportionally matched source entries
- **When entry counts differ**: A scaled approach using linear interpolation is used, similar to SRT synchronization:
- Start times are calculated using linear interpolation between the nearest source entries
- End times are calculated based on source entry durations
- The timing relationship between entries is preserved
- **Preserved from target**: All subtitle text content, formatting, cue settings, and styling.
- **Modified in target**: Timestamps are updated and cue identifiers are standardized (sequential from 1).
### Timeline Interpolation Details
The sync command uses linear interpolation to handle different entry counts between source and target files:
- **What is linear interpolation?** It's a mathematical technique for estimating values between two known points. For timeline synchronization, it creates a smooth transition between source timestamps when applied to a different number of target entries.
- **How it works:**
1. The algorithm maps each target entry position to a corresponding position in the source timeline
2. For each target position, it calculates a timestamp by interpolating between the nearest source timestamps
3. The calculation ensures proportionally distributed timestamps that maintain the rhythm of the original
- **Example:** If source file has entries at 1s, 5s, and 9s (3 entries), and target has 5 entries, the interpolated timestamps would be approximately 1s, 3s, 5s, 7s, and 9s, maintaining even spacing.
- **Benefits of linear interpolation:**
- More accurate timing when entry counts differ significantly
- Preserves the pacing and rhythm of the source timeline
- Handles both expanding (target has more entries) and contracting (target has fewer entries) scenarios
### Edge Cases
- If the source file has no timing information, the target remains unchanged.
- If source duration calculations result in negative values, a default 3-second duration is applied.
- If source duration calculations result in negative values, a default duration of zero is applied (improved from previous 3-second default).
- The command displays a warning when entry counts differ but proceeds with the scaled synchronization.
- Format-specific features from the target file (such as styling, alignment, metadata) are preserved. The sync operation only replaces timestamps, not any other formatting or content features.