Skip to content

Commit

Permalink
Allow importing placeholder chapters without start times
Browse files Browse the repository at this point in the history
  • Loading branch information
ajayyy committed Feb 12, 2025
1 parent 19efcb5 commit 2823e51
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ function messageListener(request: Message, sender: unknown, sendResponse: (respo
for (const segment of importedSegments) {
if (!sponsorTimesSubmitting.some(
(s) => Math.abs(s.segment[0] - segment.segment[0]) < 1
&& Math.abs(s.segment[1] - segment.segment[1]) < 1)) {
&& Math.abs(s.segment[1] - segment.segment[1]) < 1
&& s.description === segment.description)) {
const hasChaptersPermission = (Config.config.showCategoryWithoutPermission
|| Config.config.permissions["chapter"]);
if (segment.category === "chapter" && (!utils.getCategorySelection("chapter") || !hasChaptersPermission)) {
Expand Down
17 changes: 16 additions & 1 deletion src/utils/exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ function exportTime(segment: SponsorTime): string {

export function importTimes(data: string, videoDuration: number): SponsorTime[] {
const lines = data.split("\n");
const timeRegex = /(?:((?:\d+:)?\d+:\d+)+(?:\.\d+)?)|(?:\d+(?=s| second))/g;
const anyLineHasTime = lines.some((line) => timeRegex.test(line));

const result: SponsorTime[] = [];
for (const line of lines) {
const match = line.match(/(?:((?:\d+:)?\d+:\d+)+(?:\.\d+)?)|(?:\d+(?=s| second))/g);
const match = line.match(timeRegex);
if (match) {
const startTime = getFormattedTimeToSeconds(match[0]);
if (startTime !== null) {
Expand Down Expand Up @@ -71,6 +74,18 @@ export function importTimes(data: string, videoDuration: number): SponsorTime[]

result.push(segment);
}
} else if (!anyLineHasTime) {
// Adding chapters with placeholder times
const segment: SponsorTime = {
segment: [0, 0],
category: "chapter" as Category,
actionType: ActionType.Chapter,
description: line,
source: SponsorSourceType.Local,
UUID: generateUserID() as SegmentUUID
};

result.push(segment);
}
}

Expand Down

0 comments on commit 2823e51

Please sign in to comment.