Add support for hours in import segments

This commit is contained in:
Ajay
2022-09-02 21:42:36 -04:00
parent 4f0f8655f4
commit 533b15f44b
2 changed files with 17 additions and 1 deletions

View File

@@ -35,7 +35,7 @@ export function importTimes(data: string, videoDuration: number): SponsorTime[]
const lines = data.split("\n");
const result: SponsorTime[] = [];
for (const line of lines) {
const match = line.match(/(?:(\d+:\d+)+(?:\.\d+)?)|(?:\d+(?=s| second))/g);
const match = line.match(/(?:((?:\d+:)?\d+:\d+)+(?:\.\d+)?)|(?:\d+(?=s| second))/g);
if (match) {
const startTime = GenericUtils.getFormattedTimeToSeconds(match[0]);
if (startTime) {

View File

@@ -238,4 +238,20 @@ describe("Import segments", () => {
category: "chapter" as Category
}]);
});
it ("22. 2:04:22 some name", () => {
const input = ` 22. 2:04:22 some name
23. 2:04:22.23 some other name`;
const result = importTimes(input, 8000);
expect(result).toMatchObject([{
segment: [7462, 7462.23],
description: "some name",
category: "chapter" as Category
}, {
segment: [7462.23, 8000],
description: "some other name",
category: "chapter" as Category
}]);
});
});