Skip to content

fix: normalize YouTube caption event boundaries and timestamps - #905

Open
ArietidsZ wants to merge 2 commits into
FluentRead:mainfrom
ArietidsZ:fix/youtube-cue-normalization-20261009
Open

ArietidsZ wants to merge 2 commits into
FluentRead:mainfrom
ArietidsZ:fix/youtube-cue-normalization-20261009

Conversation

@ArietidsZ

Copy link
Copy Markdown
Contributor

YouTube timedtext events could join Unicode or quoted words without the required spaces, cross punctuation hidden by closing quotes/brackets, and accept invalid JSON3/XML timestamps. Repeated cue normalization could also change the timeline used for SRT export.

This change preserves spacing between event-level words while keeping JSON3 segments concatenated unchanged. It handles apostrophe suffixes as contractions, recognizes terminal punctuation after closing quotes/brackets, and allows common titles to continue only before a reliable capitalized name-like word. Ambiguous abbreviations, domain-like endings, and decimal-like endings keep their event boundaries.

JSON3/XML start and duration validation rejects invalid types, blank values, and negative times; cue normalization discards non-finite ends. Missing or zero durations retain inference from the next valid cue. Incremental-prefix collapse and word-stream merging converge to make repeated normalization and SRT export idempotent.

The branch is based directly on upstream af81332fb598f78b1199d103e0943e4e521a7f96. Only the data module, its tests, and a short validation note change.

Validation on that baseline, on CW with pnpm 9.12.1 and WXT 0.20.18, through the resource-safe wrapper with one worker and serial commands:

  • Red: the candidate tests on unchanged upstream source produced 71 failures out of 294.
  • Green: all 294 module tests passed; 71 related video subtitle tests passed.
  • Strict module coverage: statements, branches, functions, and lines all 100%, with no coverage exemptions.
  • Nine independent Occam ablations each caused existing assertion failures; the source was restored exactly. The module, tests, and dependency lock are byte-identical across the upstream update.
  • pnpm test:audit, pnpm compile, Chrome/Firefox/Userscript builds, the Userscript verifier, and pnpm docs:build passed.

These are offline fixture and build checks. They do not establish real YouTube response capture, online translation quality, ASR, or GPU behavior.

@ArietidsZ
ArietidsZ marked this pull request as ready for review October 9, 2026 12:25
@Bistutu

Bistutu commented Oct 9, 2026

Copy link
Copy Markdown
Member

Thank you @ArietidsZ for contributing this fix and for documenting the edge cases and validation so carefully. The examples around caption spacing, punctuation, timestamp validation, and repeated normalization are especially helpful. I'll review the implementation and reproduce the relevant checks against the current main branch before making a merge decision.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants