mirror of
https://github.com/movie-web/native-app.git
synced 2025-09-13 14:53:24 +00:00
feat: convert srt to vtt if required
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
"prettier": "@movie-web/prettier-config",
|
||||
"dependencies": {
|
||||
"@movie-web/providers": "^2.2.0",
|
||||
"srt-webvtt": "^2.0.0",
|
||||
"tmdb-ts": "^1.6.1"
|
||||
}
|
||||
}
|
||||
|
@@ -1,3 +1,5 @@
|
||||
import { default as toWebVTT } from "srt-webvtt";
|
||||
|
||||
import type {
|
||||
FileBasedStream,
|
||||
Qualities,
|
||||
@@ -11,9 +13,13 @@ import {
|
||||
targets,
|
||||
} from "@movie-web/providers";
|
||||
|
||||
export async function getVideoStream(
|
||||
media: ScrapeMedia,
|
||||
): Promise<Stream | null> {
|
||||
export async function getVideoStream({
|
||||
media,
|
||||
forceVTT,
|
||||
}: {
|
||||
media: ScrapeMedia;
|
||||
forceVTT?: boolean;
|
||||
}): Promise<Stream | null> {
|
||||
const providers = makeProviders({
|
||||
fetcher: makeStandardFetcher(fetch),
|
||||
target: targets.NATIVE,
|
||||
@@ -24,9 +30,23 @@ export async function getVideoStream(
|
||||
media,
|
||||
};
|
||||
|
||||
const results = await providers.runAll(options);
|
||||
if (!results) return null;
|
||||
return results.stream;
|
||||
const result = await providers.runAll(options);
|
||||
if (!result) return null;
|
||||
|
||||
if (forceVTT) {
|
||||
if (result.stream.captions && result.stream.captions.length > 0) {
|
||||
for (const caption of result.stream.captions) {
|
||||
if (caption.type === "srt") {
|
||||
const response = await fetch(caption.url);
|
||||
const srtSubtitle = await response.blob();
|
||||
const vttSubtitleUrl = await toWebVTT(srtSubtitle);
|
||||
caption.url = vttSubtitleUrl;
|
||||
caption.type = "vtt";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.stream;
|
||||
}
|
||||
|
||||
export function findHighestQuality(
|
||||
|
Reference in New Issue
Block a user