[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for timestamp csv import #1755

Merged
merged 2 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/edlFormats.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@

function parseTimeVal(str) {
if (str === '') return undefined;
const parsed = parseFloat(str, 10);
let timestampMatch = str.match(/^(\d{1,2}):(\d{1,2}):(\d{1,2})(?:\.(\d{1,3}))?$/);

Check failure on line 29 in src/edlFormats.js

View workflow job for this annotation

GitHub Actions / test

'timestampMatch' is never reassigned. Use 'const' instead
let parsed = undefined;

Check failure on line 30 in src/edlFormats.js

View workflow job for this annotation

GitHub Actions / test

It's not necessary to initialize 'parsed' to undefined
if (timestampMatch && timestampMatch.length === 5) {
let [, h, m, s, ms] = timestampMatch;

Check failure on line 32 in src/edlFormats.js

View workflow job for this annotation

GitHub Actions / test

'h' is never reassigned. Use 'const' instead

Check failure on line 32 in src/edlFormats.js

View workflow job for this annotation

GitHub Actions / test

'm' is never reassigned. Use 'const' instead

Check failure on line 32 in src/edlFormats.js

View workflow job for this annotation

GitHub Actions / test

's' is never reassigned. Use 'const' instead

Check failure on line 32 in src/edlFormats.js

View workflow job for this annotation

GitHub Actions / test

'ms' is never reassigned. Use 'const' instead
parsed = parseInt(h, 10) * 60 + parseInt(m, 10) * 60 + parseInt(s, 10) + parseInt(ms, 10) / 1000;
} else {
parsed = parseFloat(str, 10);
}
return processTime(parsed);
}
const mapped = rows
Expand Down
22 changes: 21 additions & 1 deletion src/edlFormats.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { it, describe, expect } from 'vitest';


import { parseYouTube, formatYouTube, parseMplayerEdl, parseXmeml, parseFcpXml, parseCsv, getTimeFromFrameNum, formatCsvFrames, getFrameCountRaw, parsePbf, parseDvAnalyzerSummaryTxt } from './edlFormats';
import { parseYouTube, formatYouTube, parseMplayerEdl, parseXmeml, parseFcpXml, parseCsv, getTimeFromFrameNum, formatCsvFrames, formatCsvHuman, getFrameCountRaw, parsePbf, parseDvAnalyzerSummaryTxt } from './edlFormats';

// eslint-disable-next-line no-underscore-dangle
const __dirname = dirname(fileURLToPath(import.meta.url));
Expand Down Expand Up @@ -211,6 +211,26 @@
expect(formatted).toEqual(csvFramesStr);
});

const csvTimestampStr = `\
00:01:54.612,00:03:09.053,A
00:05:00.448,00:07:56.194,B
00:09:27.075,00:11:44.264,C
`;

it('parses csv with timestamps', async () => {
const fps = 30;

Check failure on line 221 in src/edlFormats.test.js

View workflow job for this annotation

GitHub Actions / test

'fps' is assigned a value but never used
const parsed = await parseCsv(csvTimestampStr);

expect(parsed).toEqual([
{ end: 189.053, name: 'A', start: 114.612},

Check failure on line 225 in src/edlFormats.test.js

View workflow job for this annotation

GitHub Actions / test

A space is required before '}'
{ end: 476.194, name: 'B', start: 300.448},

Check failure on line 226 in src/edlFormats.test.js

View workflow job for this annotation

GitHub Actions / test

A space is required before '}'
{ end: 704.264, name: 'C', start: 567.075},

Check failure on line 227 in src/edlFormats.test.js

View workflow job for this annotation

GitHub Actions / test

A space is required before '}'
]);

const formatted = await formatCsvHuman(parsed);
expect(formatted).toEqual(csvTimestampStr);
});

it('parses pbf', async () => {
expect(parsePbf(await readFixture('test1.pbf', null))).toMatchSnapshot();
expect(parsePbf(await readFixture('test2.pbf', null))).toMatchSnapshot();
Expand Down
Loading