Allow importing segments with no category

Also fixes case when importing chapters when having no permission to submit chapters
This commit is contained in:
Ajay 2024-04-26 16:44:20 -04:00
parent e1d656f43f
commit 56bb22d03d
2 changed files with 17 additions and 16 deletions

View file

@ -303,7 +303,9 @@ function messageListener(request: Message, sender: unknown, sendResponse: (respo
if (!sponsorTimesSubmitting.some( if (!sponsorTimesSubmitting.some(
(s) => Math.abs(s.segment[0] - segment.segment[0]) < 1 (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)) {
if (segment.category === "chapter" && !utils.getCategorySelection("chapter")) { const hasChaptersPermission = (Config.config.showCategoryWithoutPermission
|| Config.config.permissions["chapter"]);
if (segment.category === "chapter" && (!utils.getCategorySelection("chapter") || !hasChaptersPermission)) {
segment.category = "chooseACategory" as Category; segment.category = "chooseACategory" as Category;
segment.actionType = ActionType.Skip; segment.actionType = ActionType.Skip;
segment.description = ""; segment.description = "";

View file

@ -53,24 +53,23 @@ export function importTimes(data: string, videoDuration: number): SponsorTime[]
titleRight = removeIf(split2[split2.length - 1], specialCharMatchers) titleRight = removeIf(split2[split2.length - 1], specialCharMatchers)
const title = titleLeft?.length > titleRight?.length ? titleLeft : titleRight; const title = titleLeft?.length > titleRight?.length ? titleLeft : titleRight;
if (title) { const determinedCategory = chapterNames.find(c => c.names.includes(title))?.code as Category;
const determinedCategory = chapterNames.find(c => c.names.includes(title))?.code as Category;
const segment: SponsorTime = { const category = title ? (determinedCategory ?? ("chapter" as Category)) : "chooseACategory" as Category;
segment: [startTime, getFormattedTimeToSeconds(match[1])], const segment: SponsorTime = {
category: determinedCategory ?? ("chapter" as Category), segment: [startTime, getFormattedTimeToSeconds(match[1])],
actionType: determinedCategory ? ActionType.Skip : ActionType.Chapter, category,
description: title, actionType: category === "chapter" ? ActionType.Chapter : ActionType.Skip,
source: SponsorSourceType.Local, description: category === "chapter" ? title : null,
UUID: generateUserID() as SegmentUUID source: SponsorSourceType.Local,
}; UUID: generateUserID() as SegmentUUID
};
if (result.length > 0 && result[result.length - 1].segment[1] === null) { if (result.length > 0 && result[result.length - 1].segment[1] === null) {
result[result.length - 1].segment[1] = segment.segment[0]; result[result.length - 1].segment[1] = segment.segment[0];
}
result.push(segment);
} }
result.push(segment);
} }
} }
} }