mirror of
https://github.com/movie-web/movie-web.git
synced 2024-11-11 08:45:06 +01:00
Move filterDuplicateCaptionCues
to a different file
This commit is contained in:
parent
810a12a097
commit
9f025bd12b
@ -1,26 +1,15 @@
|
||||
import { useCallback, useMemo } from "react";
|
||||
import subsrt from "subsrt-ts";
|
||||
import { ContentCaption } from "subsrt-ts/dist/types/handler";
|
||||
|
||||
import { downloadCaption, downloadWebVTT } from "@/backend/helpers/subs";
|
||||
import { Caption } from "@/stores/player/slices/source";
|
||||
import { usePlayerStore } from "@/stores/player/store";
|
||||
import { useSubtitleStore } from "@/stores/subtitles";
|
||||
|
||||
import { parseVttSubtitles } from "../utils/captions";
|
||||
|
||||
const filterDuplicateCaptionCues = (cues: ContentCaption[]) =>
|
||||
cues.reduce((acc: ContentCaption[], cap: ContentCaption) => {
|
||||
const lastCap = acc[acc.length - 1];
|
||||
const isSameAsLast =
|
||||
lastCap?.start === cap.start &&
|
||||
lastCap?.end === cap.end &&
|
||||
lastCap?.content === cap.content;
|
||||
if (lastCap === undefined || !isSameAsLast) {
|
||||
acc.push(cap);
|
||||
}
|
||||
return acc;
|
||||
}, []);
|
||||
import {
|
||||
filterDuplicateCaptionCues,
|
||||
parseVttSubtitles,
|
||||
} from "../utils/captions";
|
||||
|
||||
export function useCaptions() {
|
||||
const setLanguage = useSubtitleStore((s) => s.setLanguage);
|
||||
|
@ -50,6 +50,20 @@ export function convertSubtitlesToSrt(text: string): string {
|
||||
return srt;
|
||||
}
|
||||
|
||||
export function filterDuplicateCaptionCues(cues: ContentCaption[]) {
|
||||
return cues.reduce((acc: ContentCaption[], cap: ContentCaption) => {
|
||||
const lastCap = acc[acc.length - 1];
|
||||
const isSameAsLast =
|
||||
lastCap?.start === cap.start &&
|
||||
lastCap?.end === cap.end &&
|
||||
lastCap?.content === cap.content;
|
||||
if (lastCap === undefined || !isSameAsLast) {
|
||||
acc.push(cap);
|
||||
}
|
||||
return acc;
|
||||
}, []);
|
||||
}
|
||||
|
||||
export function parseVttSubtitles(vtt: string) {
|
||||
return parse(vtt).filter((cue) => cue.type === "caption") as CaptionCueType[];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user