feat: source selection & ugly source selector

This commit is contained in:
Adrian Castro
2024-02-18 12:22:07 +01:00
parent 68ec709c51
commit ec1300c6d6
7 changed files with 113 additions and 5 deletions

View File

@@ -1,7 +1,9 @@
import type { ScrapeMedia, Stream } from "@movie-web/providers";
import { getBuiltinSources } from "@movie-web/providers";
export const name = "provider-utils";
export * from "./video";
export * from "./util";
export type { Stream, ScrapeMedia };
export { getBuiltinSources };

View File

@@ -74,6 +74,8 @@ export async function getVideoStream({
let stream: Stream | null = null;
if (sourceId) {
onEvent && onEvent({ sourceIds: [sourceId] });
let embedOutput: EmbedOutput | undefined;
const sourceResult = await providers
@@ -81,9 +83,15 @@ export async function getVideoStream({
id: sourceId,
media,
})
.catch(() => undefined);
.catch((error: Error) => {
onEvent &&
onEvent({ id: sourceId, percentage: 0, status: "failure", error });
return undefined;
});
if (sourceResult) {
onEvent && onEvent({ id: sourceId, percentage: 50, status: "pending" });
for (const embed of sourceResult.embeds) {
const embedResult = await providers
.runEmbedScraper({
@@ -94,6 +102,8 @@ export async function getVideoStream({
if (embedResult) {
embedOutput = embedResult;
onEvent &&
onEvent({ id: embed.embedId, percentage: 100, status: "success" });
}
}
}
@@ -103,6 +113,12 @@ export async function getVideoStream({
} else if (sourceResult) {
stream = sourceResult.stream?.[0] ?? null;
}
if (stream) {
onEvent && onEvent({ id: sourceId, percentage: 100, status: "success" });
} else {
onEvent && onEvent({ id: sourceId, percentage: 100, status: "notfound" });
}
} else {
stream = await providers
.runAll(options)