Make importer import non chapters too

This commit is contained in:
Ajay
2022-09-01 16:25:43 -04:00
parent fcecd1163d
commit 69c0fe1caf

View File

@@ -1,6 +1,13 @@
import { ActionType, Category, SegmentUUID, SponsorSourceType, SponsorTime } from "../types";
import { shortCategoryName } from "./categoryUtils";
import { GenericUtils } from "./genericUtils";
import * as CompileConfig from "../../config.json";
const chapterNames = CompileConfig.categoryList.filter((code) => code !== "chapter")
.map((code) => ({
code,
name: chrome.i18n.getMessage("category_" + code)
}));
export function exportTimes(segments: SponsorTime[]): string {
let result = "";
@@ -38,10 +45,12 @@ export function importTimes(data: string, videoDuration: number): SponsorTime[]
const title = titleLeft?.length > titleRight?.length ? titleLeft : titleRight;
if (title) {
const determinedCategory = chapterNames.find(c => c.name === title)?.code as Category;
const segment: SponsorTime = {
segment: [startTime, GenericUtils.getFormattedTimeToSeconds(match[1])],
category: "chapter" as Category,
actionType: ActionType.Chapter,
category: determinedCategory ?? ("chapter" as Category),
actionType: determinedCategory ? ActionType.Skip : ActionType.Chapter,
description: title,
source: SponsorSourceType.Local,
UUID: GenericUtils.generateUserID() as SegmentUUID