Skip to content

Commit

Permalink
fix code and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mifi committed Jul 17, 2023
1 parent cb2afd0 commit 35515bb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/edlFormats.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export function parseYouTube(str) {
}

const lines = str.split('\n').map((lineStr) => {
const match = lineStr.match(/(?:([0-9]{1,}):)?([0-9]{1,2}):([0-9]{1,2})(?:\.([0-9]{3}))?[\s-:]+([^\n]*)$/);
const match = lineStr.match(/^[^0-9]*(?:([0-9]{1,}):)?([0-9]{1,2}):([0-9]{1,2})(?:\.([0-9]{3}))?:?[\s-]+([^\n]*)$/);
return parseLine(match);
}).filter((line) => line);

Expand Down
72 changes: 41 additions & 31 deletions src/edlFormats.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs/promises';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
import { it, expect } from 'vitest';
import { it, describe, expect } from 'vitest';


import { parseYouTube, formatYouTube, parseMplayerEdl, parseXmeml, parseFcpXml, parseCsv, getTimeFromFrameNum, formatCsvFrames, getFrameCountRaw, parsePbf } from './edlFormats';
Expand All @@ -24,37 +24,47 @@ const expectYouTube1 = [
{ start: 10074, end: undefined, name: 'Short - hour and hyphen' },
];

it('parseYoutube', () => {
const str = `
Jump to chapters:
0:00 00:01 Test 1
00:01 "Test 2":
00:02 00:57 double
00:01:01 Test 3
01:01:01.012 Test - 4
00:01:01.012 Test 5
01:01.012 Test 6
:01:02.012 Test 7
2:47:54 - Short - hour and hyphen
00:57:01.0123 Invalid 2
00:57:01. Invalid 3
01:15: Invalid 4
0132 Invalid 5
00:03
00:04
00:05
`;
const edl = parseYouTube(str);
expect(edl).toEqual(expectYouTube1);
});
describe('parseYouTube', () => {
it('parses different cases', () => {
const str = `
Jump to chapters:
0:00 00:01 Test 1
00:01 "Test 2":
00:02 00:57 double
00:01:01 Test 3
01:01:01.012 Test - 4
00:01:01.012 Test 5
01:01.012 Test 6
:01:02.012 Test 7
2:47:54 - Short - hour and hyphen
00:57:01.0123 Invalid 2
00:57:01. Invalid 3
01:15:: Invalid 4
0132 Invalid 5
00:03
00:04
00:05
`;
const edl = parseYouTube(str);
expect(edl).toEqual(expectYouTube1);
});

it('parseYouTube eol', () => {
const str = ' 00:00 Test 1\n00:01 Test 2';
const edl = parseYouTube(str);
expect(edl).toEqual([
{ start: 0, end: 1, name: 'Test 1' },
{ start: 1, end: undefined, name: 'Test 2' },
]);
it('eol', () => {
const str = ' 00:00 Test 1\n00:01 Test 2';
const edl = parseYouTube(str);
expect(edl).toEqual([
{ start: 0, end: 1, name: 'Test 1' },
{ start: 1, end: undefined, name: 'Test 2' },
]);
});

it('colon after time', () => {
const str = ' 00:00: Test 1';
const edl = parseYouTube(str);
expect(edl).toEqual([
{ start: 0, end: undefined, name: 'Test 1' },
]);
});
});

it('formatYouTube', () => {
Expand Down

0 comments on commit 35515bb

Please sign in to comment.