Skip to content

Commit

Permalink
fix: parse correctly even if firstlime is a timeblock
Browse files Browse the repository at this point in the history
  • Loading branch information
ste-xx committed Jul 19, 2024
1 parent b6ea55c commit 04763b8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/vttParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const VttMachine: () => Machine = () => ({
const { tokens, pos } = params;
if (tokens.length <= pos) {
return { next: TRANSITION_NAMES.FINISH, params };
} else if(tokens[pos].includes(":")){
} else if(tokens[pos].includes(":") && !tokens[pos].includes("-->") ){
return { next: TRANSITION_NAMES.LEGACY_HEADER, params: { ...params, pos: pos + 1 } };
} else {
return { next: TRANSITION_NAMES.ID_OR_NOTE_OR_STYLE_OR_REGION, params };
Expand Down
6 changes: 4 additions & 2 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import vttMultiWhitespaces from './vttMultiWhitespaces';
import vttWithEmptyTextLines from './vttWithEmptyTextLines';
import vttWithMissingNewLineInLastLine from './vttWithMissingNewLineInLastLine';
import vtt from './vtt';
import vttDirectTimestamp from './vttDirectTimestamp';
import vttWithLegacyMetaHeader from './vttWithLegacyMetaHeader';
import vttWithRegionHeader from './vttWithRegion';
import vttWithoutIdentifier from './vttWithoutIdentifier';
Expand All @@ -33,6 +34,7 @@ describe('srt-vtt-parser', () => {
${vtt} | ${result} | ${'should parse simple vtt file'}
${vttMultiWhitespaces} | ${result} | ${'should parse vtt file with multiple whitespaces'}
${vttWithMissingNewLineInLastLine} | ${result} | ${'should parse vtt file even the last line does not have a new line'}
${vttDirectTimestamp} | ${resultWithoutId} | ${'should parse vtt file with direct time stamp'}
${vttWithEmptyTextLines} | ${resultWithEmptyTextLines} | ${'should parse vtt file with empty text lines'}
${vttWithoutIdentifier} | ${resultWithoutId} | ${'should parse vtt file without identifier'}
${vttWithMixedIdentifier} | ${resultWithMixedId} | ${'should parse vtt file with mixed identifier'}
Expand All @@ -49,10 +51,10 @@ describe('srt-vtt-parser', () => {
});

it('parse whole srt file', () => {
// console.warn(parse(driveSrt));
console.warn(parse(driveSrt));
});

it('parse whole vtt file', async () => {
// console.warn(await parse(pulpfictionVtt));
console.warn(await parse(pulpfictionVtt));
});
});
11 changes: 11 additions & 0 deletions test/vttDirectTimestamp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default `WEBVTT
00:01:42.821 --> 00:01:44.289
(SIREN WAILING IN DISTANCE)
multiline test
00:01:45.365 --> 00:01:48.084
<i>DRIVER: There's 100,000 streets in this city.</i>
00:01:49.077 --> 00:01:51.421
You don't need to know the route.
`
1 change: 0 additions & 1 deletion test/vttWithEmptyTextLines.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export default `WEBVTT
1
00:01:42.821 --> 00:01:44.289
(SIREN WAILING IN DISTANCE)
Expand Down

0 comments on commit 04763b8

Please sign in to comment.