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:
parent
b96fca8ed8
commit
175ffbc71f
1 changed files with 14 additions and 10 deletions
|
|
@ -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
|
||||
* subtitle and the previous subtitle, and merges them into a single subtitle.
|
||||
*/
|
||||
if (
|
||||
previousLine?.start == x.start &&
|
||||
previousLine.type == x.type &&
|
||||
previousLine.style == x.style &&
|
||||
!previousLine?.text.includes('\\pos') &&
|
||||
!x.text.includes('\\pos')
|
||||
) {
|
||||
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);
|
||||
if (previousLine) {
|
||||
const previousStart = parseFloat(previousLine.start.split(':').join('').split('.').join(''));
|
||||
const currentStart = parseFloat(x.start.split(':').join('').split('.').join(''));
|
||||
if (
|
||||
(currentStart - previousStart) <= 2 &&
|
||||
previousLine.type == x.type &&
|
||||
previousLine.style == x.style &&
|
||||
!previousLine.text.includes('\\pos') &&
|
||||
!x.text.includes('\\pos')
|
||||
) {
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue