mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-06 11:37:02 +03:00
Fix zero start time breaking
This commit is contained in:
@@ -38,7 +38,7 @@ export function importTimes(data: string, videoDuration: number): SponsorTime[]
|
|||||||
const match = line.match(/(?:((?:\d+:)?\d+:\d+)+(?:\.\d+)?)|(?:\d+(?=s| second))/g);
|
const match = line.match(/(?:((?:\d+:)?\d+:\d+)+(?:\.\d+)?)|(?:\d+(?=s| second))/g);
|
||||||
if (match) {
|
if (match) {
|
||||||
const startTime = GenericUtils.getFormattedTimeToSeconds(match[0]);
|
const startTime = GenericUtils.getFormattedTimeToSeconds(match[0]);
|
||||||
if (startTime) {
|
if (startTime !== null) {
|
||||||
const specialCharsMatcher = /^(?:\s+seconds?)?[-:()\s]*|(?:\s+at)?[-:()\s]+$/g
|
const specialCharsMatcher = /^(?:\s+seconds?)?[-:()\s]*|(?:\s+at)?[-:()\s]+$/g
|
||||||
const titleLeft = line.split(match[0])[0].replace(specialCharsMatcher, "");
|
const titleLeft = line.split(match[0])[0].replace(specialCharsMatcher, "");
|
||||||
let titleRight = null;
|
let titleRight = null;
|
||||||
|
|||||||
@@ -254,4 +254,25 @@ describe("Import segments", () => {
|
|||||||
category: "chapter" as Category
|
category: "chapter" as Category
|
||||||
}]);
|
}]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it ("00:00", () => {
|
||||||
|
const input = ` 00:00 Cap 1
|
||||||
|
00:10 Cap 2
|
||||||
|
00:12 Cap 3`;
|
||||||
|
|
||||||
|
const result = importTimes(input, 8000);
|
||||||
|
expect(result).toMatchObject([{
|
||||||
|
segment: [0, 10],
|
||||||
|
description: "Cap 1",
|
||||||
|
category: "chapter" as Category
|
||||||
|
}, {
|
||||||
|
segment: [10, 12],
|
||||||
|
description: "Cap 2",
|
||||||
|
category: "chapter" as Category
|
||||||
|
}, {
|
||||||
|
segment: [12, 8000],
|
||||||
|
description: "Cap 3",
|
||||||
|
category: "chapter" as Category
|
||||||
|
}]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user