mirror of
https://github.com/movie-web/movie-web.git
synced 2024-11-13 10:15:11 +01:00
Add provider-api to source selection menu
This commit is contained in:
parent
15d97dda02
commit
ca2e20fdbc
@ -5,6 +5,10 @@ import {
|
|||||||
} from "@movie-web/providers";
|
} from "@movie-web/providers";
|
||||||
import { useAsyncFn } from "react-use";
|
import { useAsyncFn } from "react-use";
|
||||||
|
|
||||||
|
import {
|
||||||
|
connectServerSideEvents,
|
||||||
|
makeProviderUrl,
|
||||||
|
} from "@/backend/helpers/providerApi";
|
||||||
import {
|
import {
|
||||||
scrapeSourceOutputToProviderMetric,
|
scrapeSourceOutputToProviderMetric,
|
||||||
useReportProviders,
|
useReportProviders,
|
||||||
@ -14,7 +18,7 @@ import { convertRunoutputToSource } from "@/components/player/utils/convertRunou
|
|||||||
import { useOverlayRouter } from "@/hooks/useOverlayRouter";
|
import { useOverlayRouter } from "@/hooks/useOverlayRouter";
|
||||||
import { metaToScrapeMedia } from "@/stores/player/slices/source";
|
import { metaToScrapeMedia } from "@/stores/player/slices/source";
|
||||||
import { usePlayerStore } from "@/stores/player/store";
|
import { usePlayerStore } from "@/stores/player/store";
|
||||||
import { providers } from "@/utils/providers";
|
import { getLoadbalancedProviderApiUrl, providers } from "@/utils/providers";
|
||||||
|
|
||||||
export function useEmbedScraping(
|
export function useEmbedScraping(
|
||||||
routerId: string,
|
routerId: string,
|
||||||
@ -31,13 +35,23 @@ export function useEmbedScraping(
|
|||||||
const { report } = useReportProviders();
|
const { report } = useReportProviders();
|
||||||
|
|
||||||
const [request, run] = useAsyncFn(async () => {
|
const [request, run] = useAsyncFn(async () => {
|
||||||
|
const providerApiUrl = getLoadbalancedProviderApiUrl();
|
||||||
let result: EmbedOutput | undefined;
|
let result: EmbedOutput | undefined;
|
||||||
if (!meta) return;
|
if (!meta) return;
|
||||||
try {
|
try {
|
||||||
result = await providers.runEmbedScraper({
|
if (providerApiUrl) {
|
||||||
id: embedId,
|
const baseUrlMaker = makeProviderUrl(providerApiUrl);
|
||||||
url,
|
const conn = connectServerSideEvents<EmbedOutput>(
|
||||||
});
|
baseUrlMaker.scrapeEmbed(embedId, url),
|
||||||
|
["completed"]
|
||||||
|
);
|
||||||
|
result = await conn.promise();
|
||||||
|
} else {
|
||||||
|
result = await providers.runEmbedScraper({
|
||||||
|
id: embedId,
|
||||||
|
url,
|
||||||
|
});
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`Failed to scrape ${embedId}`, err);
|
console.error(`Failed to scrape ${embedId}`, err);
|
||||||
const notFound = err instanceof NotFoundError;
|
const notFound = err instanceof NotFoundError;
|
||||||
@ -85,13 +99,23 @@ export function useSourceScraping(sourceId: string | null, routerId: string) {
|
|||||||
const [request, run] = useAsyncFn(async () => {
|
const [request, run] = useAsyncFn(async () => {
|
||||||
if (!sourceId || !meta) return null;
|
if (!sourceId || !meta) return null;
|
||||||
const scrapeMedia = metaToScrapeMedia(meta);
|
const scrapeMedia = metaToScrapeMedia(meta);
|
||||||
|
const providerApiUrl = getLoadbalancedProviderApiUrl();
|
||||||
|
|
||||||
let result: SourcererOutput | undefined;
|
let result: SourcererOutput | undefined;
|
||||||
try {
|
try {
|
||||||
result = await providers.runSourceScraper({
|
if (providerApiUrl) {
|
||||||
id: sourceId,
|
const baseUrlMaker = makeProviderUrl(providerApiUrl);
|
||||||
media: scrapeMedia,
|
const conn = connectServerSideEvents<SourcererOutput>(
|
||||||
});
|
baseUrlMaker.scrapeSource(sourceId, scrapeMedia),
|
||||||
|
["completed"]
|
||||||
|
);
|
||||||
|
result = await conn.promise();
|
||||||
|
} else {
|
||||||
|
result = await providers.runSourceScraper({
|
||||||
|
id: sourceId,
|
||||||
|
media: scrapeMedia,
|
||||||
|
});
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`Failed to scrape ${sourceId}`, err);
|
console.error(`Failed to scrape ${sourceId}`, err);
|
||||||
const notFound = err instanceof NotFoundError;
|
const notFound = err instanceof NotFoundError;
|
||||||
@ -120,10 +144,22 @@ export function useSourceScraping(sourceId: string | null, routerId: string) {
|
|||||||
let embedResult: EmbedOutput | undefined;
|
let embedResult: EmbedOutput | undefined;
|
||||||
if (!meta) return;
|
if (!meta) return;
|
||||||
try {
|
try {
|
||||||
embedResult = await providers.runEmbedScraper({
|
if (providerApiUrl) {
|
||||||
id: result.embeds[0].embedId,
|
const baseUrlMaker = makeProviderUrl(providerApiUrl);
|
||||||
url: result.embeds[0].url,
|
const conn = connectServerSideEvents<EmbedOutput>(
|
||||||
});
|
baseUrlMaker.scrapeEmbed(
|
||||||
|
result.embeds[0].embedId,
|
||||||
|
result.embeds[0].url
|
||||||
|
),
|
||||||
|
["completed"]
|
||||||
|
);
|
||||||
|
embedResult = await conn.promise();
|
||||||
|
} else {
|
||||||
|
embedResult = await providers.runEmbedScraper({
|
||||||
|
id: result.embeds[0].embedId,
|
||||||
|
url: result.embeds[0].url,
|
||||||
|
});
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`Failed to scrape ${result.embeds[0].embedId}`, err);
|
console.error(`Failed to scrape ${result.embeds[0].embedId}`, err);
|
||||||
const notFound = err instanceof NotFoundError;
|
const notFound = err instanceof NotFoundError;
|
||||||
|
Loading…
Reference in New Issue
Block a user