Skip to content

Commit

Permalink
fix(SSA): Support files with line breaks that are not necessary (#6947)
Browse files Browse the repository at this point in the history
Related to #6943
  • Loading branch information
avelad authored Jul 1, 2024
1 parent d719328 commit 88431b6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
29 changes: 22 additions & 7 deletions lib/text/ssa_text_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,39 @@ shaka.text.SsaTextParser = class {
events: '',
};

let tag = null;
let lines = null;
const parts = str.split(/\r?\n\s*\r?\n/);
for (const part of parts) {
lines = part;
// SSA content
const match = SsaTextParser.ssaContent_.exec(part);
if (match) {
const tag = match[1];
const lines = match[2];
if (tag == 'V4 Styles' || tag == 'V4+ Styles') {
tag = match[1];
lines = match[2];
}
if (tag == 'V4 Styles' || tag == 'V4+ Styles') {
section.styles = lines;
if (section.events) {
section.styles += '\n' + lines;
} else {
section.styles = lines;
continue;
}
if (tag == 'Events') {
continue;
}
if (tag == 'Events') {
if (section.events) {
section.events += '\n' + lines;
} else {
section.events = lines;
continue;
}
continue;
}
if (tag == 'Script Info') {
continue;
}
shaka.log.warning('SsaTextParser parser encountered an unknown part.',
part);
lines);
}

// Process styles
Expand Down
4 changes: 2 additions & 2 deletions test/text/ssa_text_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ describe('SsaTextParser', () => {
'Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, ' +
'Effect, Text\n' +
'Dialogue: 0,0:00:00.00,0:00:02.00,DefaultVCD, NTP,0000,0000,0000' +
',,{\\pos(400,570)}Test\n' +
',,{\\pos(400,570)}Test\n\n' +
'Dialogue: 0,0:00:04.50,0:00:06.10,DefaultVCD, NTP,0000,0000,0000' +
',,{\\pos(400,570)}Test2\n' +
',,{\\pos(400,570)}Test2\n\n' +
'Dialogue: 0,0:00:08.01,0:00:10.10,DefaultVCD, NTP,0000,0000,0000' +
',,{\\pos(400,570)}Test3',
{periodStart: 0, segmentStart: 0, segmentEnd: 0, vttOffset: 0});
Expand Down

0 comments on commit 88431b6

Please sign in to comment.