Skip to content

Commit

Permalink
Don't remove trailing end bracket when not starting with bracket
Browse files Browse the repository at this point in the history
  • Loading branch information
ajayyy committed Dec 19, 2022
1 parent 3379189 commit 35b8a34
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/utils/exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export function importTimes(data: string, videoDuration: number): SponsorTime[]
if (match) {
const startTime = GenericUtils.getFormattedTimeToSeconds(match[0]);
if (startTime !== null) {
const specialCharsMatcher = /^(?:\s+seconds?)?[-:()\s]*|(?:\s+at)?[-:()\s]+$/g
// Remove "seconds", "at", special characters, and ")" if there was a "("
const specialCharsMatcher = /^(?:\s+seconds?)?[-:()\s]*|(?:\s+at)?[-:(\s]+$|(?<=^\s*\(.+)[-:()\s]*$/g
const titleLeft = line.split(match[0])[0].replace(specialCharsMatcher, "");
let titleRight = null;
const split2 = line.split(match[1] || match[0]);
Expand Down
16 changes: 16 additions & 0 deletions test/exporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,20 @@ describe("Import segments", () => {
category: "chapter" as Category
}]);
});

it ("0:00 G¹ (Tangent Continuity)", () => {
const input = ` 0:00 G¹ (Tangent Continuity)
0:01 G² (Tangent Continuity)`;

const result = importTimes(input, 8000);
expect(result).toMatchObject([{
segment: [0, 1],
description: "G¹ (Tangent Continuity)",
category: "chapter" as Category
}, {
segment: [1, 8000],
description: "G² (Tangent Continuity)",
category: "chapter" as Category
}]);
});
});

0 comments on commit 35b8a34

Please sign in to comment.