mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-12 14:37:23 +03:00
Make importer import non chapters too
This commit is contained in:
@@ -1,6 +1,13 @@
|
|||||||
import { ActionType, Category, SegmentUUID, SponsorSourceType, SponsorTime } from "../types";
|
import { ActionType, Category, SegmentUUID, SponsorSourceType, SponsorTime } from "../types";
|
||||||
import { shortCategoryName } from "./categoryUtils";
|
import { shortCategoryName } from "./categoryUtils";
|
||||||
import { GenericUtils } from "./genericUtils";
|
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 {
|
export function exportTimes(segments: SponsorTime[]): string {
|
||||||
let result = "";
|
let result = "";
|
||||||
@@ -38,10 +45,12 @@ export function importTimes(data: string, videoDuration: number): SponsorTime[]
|
|||||||
|
|
||||||
const title = titleLeft?.length > titleRight?.length ? titleLeft : titleRight;
|
const title = titleLeft?.length > titleRight?.length ? titleLeft : titleRight;
|
||||||
if (title) {
|
if (title) {
|
||||||
|
const determinedCategory = chapterNames.find(c => c.name === title)?.code as Category;
|
||||||
|
|
||||||
const segment: SponsorTime = {
|
const segment: SponsorTime = {
|
||||||
segment: [startTime, GenericUtils.getFormattedTimeToSeconds(match[1])],
|
segment: [startTime, GenericUtils.getFormattedTimeToSeconds(match[1])],
|
||||||
category: "chapter" as Category,
|
category: determinedCategory ?? ("chapter" as Category),
|
||||||
actionType: ActionType.Chapter,
|
actionType: determinedCategory ? ActionType.Skip : ActionType.Chapter,
|
||||||
description: title,
|
description: title,
|
||||||
source: SponsorSourceType.Local,
|
source: SponsorSourceType.Local,
|
||||||
UUID: GenericUtils.generateUserID() as SegmentUUID
|
UUID: GenericUtils.generateUserID() as SegmentUUID
|
||||||
|
|||||||
Reference in New Issue
Block a user