fix(subtitles): collapse duplicate ASS events and decode text once (#186)

This commit is contained in:
2026-08-10 22:21:44 -07:00
committed by GitHub
parent 2fefc83e3f
commit 7b0fbdf254
14 changed files with 1323 additions and 88 deletions
+6 -13
View File
@@ -16,6 +16,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { normalizePlainSubtitleText } from './core/services/ass-text';
interface TimingEntry {
startTime: number;
endTime: number;
@@ -191,23 +193,14 @@ export class SubtitleTimingTracker {
return costs[shorter.length] || 0;
}
// Both sides take text mpv has already decoded from ASS; only whitespace differs
// between the lookup key (single line) and the display form (line breaks kept).
private normalizeText(text: string): string {
return text
.replace(/\\N/g, ' ')
.replace(/\\n/g, ' ')
.replace(/\n/g, ' ')
.replace(/{[^}]*}/g, '')
.replace(/\s+/g, ' ')
.trim();
return normalizePlainSubtitleText(text, { collapseLineBreaks: true });
}
private prepareDisplayText(text: string): string {
// Convert ASS/SSA newlines to real newlines, strip tags
return text
.replace(/\\N/g, '\n')
.replace(/\\n/g, '\n')
.replace(/{[^}]*}/g, '')
.trim();
return normalizePlainSubtitleText(text);
}
private startCleanup(): void {