kopia lustrzana https://github.com/mifi/lossless-cut
fix youtube parsing short hours bug
also allow hyphen before chapter name fixes #1102pull/1106/head
rodzic
b9578aa657
commit
2d885496cb
|
@ -150,10 +150,6 @@ export function parseXmeml(xmlStr) {
|
|||
}
|
||||
|
||||
export function parseYouTube(str) {
|
||||
const regex = /(?:([0-9]{2,}):)?([0-9]{1,2}):([0-9]{1,2})(?:\.([0-9]{3}))?[^\S\n]+([^\n]*)\n/g;
|
||||
|
||||
const lines = [];
|
||||
|
||||
function parseLine(match) {
|
||||
if (!match) return undefined;
|
||||
const [, hourStr, minStr, secStr, msStr, name] = match;
|
||||
|
@ -167,11 +163,10 @@ export function parseYouTube(str) {
|
|||
return { time, name };
|
||||
}
|
||||
|
||||
let m;
|
||||
// eslint-disable-next-line no-cond-assign
|
||||
while ((m = regex.exec(`${str}\n`))) {
|
||||
lines.push(parseLine(m));
|
||||
}
|
||||
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]*)$/);
|
||||
return parseLine(match);
|
||||
}).filter((line) => line);
|
||||
|
||||
const linesSorted = sortBy(lines, (l) => l.time);
|
||||
|
||||
|
|
|
@ -5,6 +5,19 @@ import { parseYouTube, formatYouTube, parseMplayerEdl, parseXmeml, parseCsv, get
|
|||
|
||||
const readFixture = async (name, encoding = 'utf-8') => fs.readFile(join(__dirname, 'fixtures', name), encoding);
|
||||
|
||||
const expectYouTube1 = [
|
||||
{ start: 0, end: 1, name: '00:01 Test 1' },
|
||||
{ start: 1, end: 2, name: '"Test 2":' },
|
||||
{ start: 2, end: 4, name: '00:57 double' },
|
||||
{ start: 4, end: 5, name: '' },
|
||||
{ start: 5, end: 61, name: '' },
|
||||
{ start: 61, end: 61.012, name: 'Test 3' },
|
||||
{ start: 61.012, end: 62.012, name: 'Test 6' },
|
||||
{ start: 62.012, end: 3661.012, name: 'Test 7' },
|
||||
{ start: 3661.012, end: 10074, name: 'Test - 4' },
|
||||
{ start: 10074, end: undefined, name: 'Short - hour and hyphen' },
|
||||
];
|
||||
|
||||
it('parseYoutube', () => {
|
||||
const str = `
|
||||
Jump to chapters:
|
||||
|
@ -12,10 +25,11 @@ Jump to chapters:
|
|||
00:01 "Test 2":
|
||||
00:02 00:57 double
|
||||
00:01:01 Test 3
|
||||
01:01:01.012 Test 4
|
||||
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
|
||||
|
@ -25,17 +39,7 @@ Jump to chapters:
|
|||
00:05
|
||||
`;
|
||||
const edl = parseYouTube(str);
|
||||
expect(edl).toEqual([
|
||||
{ start: 0, end: 1, name: '00:01 Test 1' },
|
||||
{ start: 1, end: 2, name: '"Test 2":' },
|
||||
{ start: 2, end: 4, name: '00:57 double' },
|
||||
{ start: 4, end: 5, name: '' },
|
||||
{ start: 5, end: 61, name: '' },
|
||||
{ start: 61, end: 61.012, name: 'Test 3' },
|
||||
{ start: 61.012, end: 62.012, name: 'Test 6' },
|
||||
{ start: 62.012, end: 3661.012, name: 'Test 7' },
|
||||
{ start: 3661.012, end: undefined, name: 'Test 4' },
|
||||
]);
|
||||
expect(edl).toEqual(expectYouTube1);
|
||||
});
|
||||
|
||||
it('parseYouTube eol', () => {
|
||||
|
@ -64,6 +68,21 @@ it('formatYouTube', () => {
|
|||
]);
|
||||
});
|
||||
|
||||
it('formatYouTube 2', () => {
|
||||
expect(formatYouTube(expectYouTube1).split('\n')).toEqual([
|
||||
'0:00 00:01 Test 1',
|
||||
'0:01 "Test 2":',
|
||||
'0:02 00:57 double',
|
||||
'0:04',
|
||||
'0:05',
|
||||
'1:01 Test 3',
|
||||
'1:01 Test 6',
|
||||
'1:02 Test 7',
|
||||
'1:01:01 Test - 4',
|
||||
'2:47:54 Short - hour and hyphen',
|
||||
]);
|
||||
});
|
||||
|
||||
// https://kodi.wiki/view/Edit_decision_list
|
||||
// http://www.mplayerhq.hu/DOCS/HTML/en/edl.html
|
||||
it('parseMplayerEdl', async () => {
|
||||
|
|
Ładowanie…
Reference in New Issue