mirror of
https://github.com/sussy-code/smov.git
synced 2025-01-01 16:37:39 +01:00
Abortable scraping
Co-authored-by: mrjvs <mistrjvs@gmail.com>
This commit is contained in:
parent
95c5e73996
commit
ca0ccb240e
1 changed files with 4 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
import { ProviderControls, ScrapeMedia } from "@movie-web/providers";
|
import { ProviderControls, ScrapeMedia } from "@movie-web/providers";
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
import { useEffect, useRef } from "react";
|
import { useEffect, useRef } from "react";
|
||||||
|
import { useMountedState } from "react-use";
|
||||||
import type { AsyncReturnType } from "type-fest";
|
import type { AsyncReturnType } from "type-fest";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -30,6 +31,7 @@ export interface ScrapingProps {
|
||||||
export function ScrapingPart(props: ScrapingProps) {
|
export function ScrapingPart(props: ScrapingProps) {
|
||||||
const { report } = useReportProviders();
|
const { report } = useReportProviders();
|
||||||
const { startScraping, sourceOrder, sources, currentSource } = useScrape();
|
const { startScraping, sourceOrder, sources, currentSource } = useScrape();
|
||||||
|
const isMounted = useMountedState();
|
||||||
|
|
||||||
const containerRef = useRef<HTMLDivElement | null>(null);
|
const containerRef = useRef<HTMLDivElement | null>(null);
|
||||||
const listRef = useRef<HTMLDivElement | null>(null);
|
const listRef = useRef<HTMLDivElement | null>(null);
|
||||||
|
@ -57,6 +59,7 @@ export function ScrapingPart(props: ScrapingProps) {
|
||||||
started.current = true;
|
started.current = true;
|
||||||
(async () => {
|
(async () => {
|
||||||
const output = await startScraping(props.media);
|
const output = await startScraping(props.media);
|
||||||
|
if (!isMounted()) return;
|
||||||
props.onResult?.(
|
props.onResult?.(
|
||||||
resultRef.current.sources,
|
resultRef.current.sources,
|
||||||
resultRef.current.sourceOrder
|
resultRef.current.sourceOrder
|
||||||
|
@ -70,7 +73,7 @@ export function ScrapingPart(props: ScrapingProps) {
|
||||||
);
|
);
|
||||||
props.onGetStream?.(output);
|
props.onGetStream?.(output);
|
||||||
})();
|
})();
|
||||||
}, [startScraping, props, report]);
|
}, [startScraping, props, report, isMounted]);
|
||||||
|
|
||||||
const currentProvider = sourceOrder.find(
|
const currentProvider = sourceOrder.find(
|
||||||
(s) => sources[s.id].status === "pending"
|
(s) => sources[s.id].status === "pending"
|
||||||
|
|
Loading…
Reference in a new issue