mirror of
https://github.com/sussy-code/smov.git
synced 2025-01-08 17:27:40 +01:00
f97b84516b
Co-authored-by: Jip Frijlink <JipFr@users.noreply.github.com> Co-authored-by: James Hawkins <jhawki2005@gmail.com>
34 lines
909 B
TypeScript
34 lines
909 B
TypeScript
import { mwFetch, proxiedFetch } from "@/backend/helpers/fetch";
|
|
import { MWCaption, MWCaptionType } from "@/backend/helpers/streams";
|
|
import toWebVTT from "srt-webvtt";
|
|
|
|
export async function getCaptionUrl(caption: MWCaption): Promise<string> {
|
|
if (caption.type === MWCaptionType.SRT) {
|
|
let captionBlob: Blob;
|
|
|
|
if (caption.needsProxy) {
|
|
captionBlob = await proxiedFetch<Blob>(caption.url, {
|
|
responseType: "blob" as any,
|
|
});
|
|
} else {
|
|
captionBlob = await mwFetch<Blob>(caption.url, {
|
|
responseType: "blob" as any,
|
|
});
|
|
}
|
|
|
|
return toWebVTT(captionBlob);
|
|
}
|
|
|
|
if (caption.type === MWCaptionType.VTT) {
|
|
if (caption.needsProxy) {
|
|
const blob = await proxiedFetch<Blob>(caption.url, {
|
|
responseType: "blob" as any,
|
|
});
|
|
return URL.createObjectURL(blob);
|
|
}
|
|
|
|
return caption.url;
|
|
}
|
|
|
|
throw new Error("invalid type");
|
|
}
|