mirror of
https://github.com/movie-web/movie-web.git
synced 2024-11-13 12:45:10 +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 { useCallback, useMemo } from "react";
|
||||||
import subsrt from "subsrt-ts";
|
import subsrt from "subsrt-ts";
|
||||||
import { ContentCaption } from "subsrt-ts/dist/types/handler";
|
|
||||||
|
|
||||||
import { downloadCaption, downloadWebVTT } from "@/backend/helpers/subs";
|
import { downloadCaption, downloadWebVTT } from "@/backend/helpers/subs";
|
||||||
import { Caption } from "@/stores/player/slices/source";
|
import { Caption } from "@/stores/player/slices/source";
|
||||||
import { usePlayerStore } from "@/stores/player/store";
|
import { usePlayerStore } from "@/stores/player/store";
|
||||||
import { useSubtitleStore } from "@/stores/subtitles";
|
import { useSubtitleStore } from "@/stores/subtitles";
|
||||||
|
|
||||||
import { parseVttSubtitles } from "../utils/captions";
|
import {
|
||||||
|
filterDuplicateCaptionCues,
|
||||||
const filterDuplicateCaptionCues = (cues: ContentCaption[]) =>
|
parseVttSubtitles,
|
||||||
cues.reduce((acc: ContentCaption[], cap: ContentCaption) => {
|
} from "../utils/captions";
|
||||||
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 useCaptions() {
|
export function useCaptions() {
|
||||||
const setLanguage = useSubtitleStore((s) => s.setLanguage);
|
const setLanguage = useSubtitleStore((s) => s.setLanguage);
|
||||||
|
@ -50,6 +50,20 @@ export function convertSubtitlesToSrt(text: string): string {
|
|||||||
return srt;
|
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) {
|
export function parseVttSubtitles(vtt: string) {
|
||||||
return parse(vtt).filter((cue) => cue.type === "caption") as CaptionCueType[];
|
return parse(vtt).filter((cue) => cue.type === "caption") as CaptionCueType[];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user