mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-06 11:37:02 +03:00
Add support for hours in import segments
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
}]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user