vtt2ass: Improve Merging Logic for subtitles

Improves merging logic for subtitles by adding a check to see if the time is within a deviation of 2. This code is cursed. Addresses #608
This commit is contained in:
AnimeDL 2024-03-24 15:15:45 -07:00
parent b96fca8ed8
commit 175ffbc71f

View file

@ -286,16 +286,20 @@ function convert(css: Css, vtt: Vtt[]) {
* This checks if a subtitle should be multi-line, and if it is, pops the just inserted * This checks if a subtitle should be multi-line, and if it is, pops the just inserted
* subtitle and the previous subtitle, and merges them into a single subtitle. * subtitle and the previous subtitle, and merges them into a single subtitle.
*/ */
if ( if (previousLine) {
previousLine?.start == x.start && const previousStart = parseFloat(previousLine.start.split(':').join('').split('.').join(''));
previousLine.type == x.type && const currentStart = parseFloat(x.start.split(':').join('').split('.').join(''));
previousLine.style == x.style && if (
!previousLine?.text.includes('\\pos') && (currentStart - previousStart) <= 2 &&
!x.text.includes('\\pos') previousLine.type == x.type &&
) { previousLine.style == x.style &&
events[x.type as keyof typeof events].pop(); !previousLine.text.includes('\\pos') &&
const previousLinePop = events[x.type as keyof typeof events].pop(); !x.text.includes('\\pos')
events[x.type as keyof typeof events].push(previousLinePop + '\\N'+x.text); ) {
events[x.type as keyof typeof events].pop();
const previousLinePop = events[x.type as keyof typeof events].pop();
events[x.type as keyof typeof events].push(previousLinePop + '\\N'+x.text);
}
} }
previousLine = x; previousLine = x;
} }