Commit 77f9f97
fix(subtitles): implement comprehensive Chinese character loss detection and fallback for ASS subtitle parsing (#229)
- Add intelligent character loss detection to identify when subsrt library drops Chinese characters
- Implement custom ASS parser as fallback mechanism for problematic subtitle files
- Add comprehensive test suite covering 51 edge cases and boundary conditions
- Fix ASS tag stripping order to prioritize newline processing before style removal
- Enhance bilingual subtitle separation with improved script detection
- Add detailed logging for debugging subtitle parsing issues
Changes:
- parseWithSubsrt: Add hasChineseCharacterLoss detection and parseCustomAss fallback
- Add parseCustomAss: Complete ASS format parser with proper Dialogue handling
- Add parseAssDialogue: Parse ASS Dialogue lines with accurate time parsing
- Add hasChineseCharacterLoss: Detect Chinese character loss by comparing original vs parsed content
- Update stripAssTags: Process newlines before style tags to prevent character truncation
- Add SubtitleReader.comprehensive.test.ts: 51 comprehensive tests covering all scenarios
- Update SubtitleReader.test.ts: Add regression test for \N newline character loss
This fix resolves the critical issue where subsrt library was dropping the first Chinese character
(《老友记》 → 老友记) in ASS subtitles and ensures robust parsing of various subtitle formats
including edge cases with complex styling and bilingual content.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude <noreply@anthropic.com>1 parent 16a880e commit 77f9f97
3 files changed
Lines changed: 986 additions & 15 deletions
File tree
- src/renderer/src/services/subtitles
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
146 | | - | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
147 | 168 | | |
148 | 169 | | |
149 | 170 | | |
| |||
165 | 186 | | |
166 | 187 | | |
167 | 188 | | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
168 | 307 | | |
169 | 308 | | |
170 | 309 | | |
| |||
449 | 588 | | |
450 | 589 | | |
451 | 590 | | |
452 | | - | |
453 | | - | |
454 | | - | |
455 | | - | |
456 | | - | |
457 | | - | |
458 | | - | |
459 | | - | |
460 | | - | |
461 | | - | |
462 | | - | |
463 | 591 | | |
464 | 592 | | |
465 | 593 | | |
| |||
469 | 597 | | |
470 | 598 | | |
471 | 599 | | |
| 600 | + | |
472 | 601 | | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
473 | 605 | | |
474 | 606 | | |
475 | 607 | | |
476 | | - | |
477 | | - | |
478 | | - | |
479 | 608 | | |
480 | 609 | | |
481 | 610 | | |
0 commit comments