mirror of
https://github.com/p-stream/p-stream.git
synced 2026-01-11 20:10:32 +00:00
remove warning part and treat scraping error as playback error to auto resume
This commit is contained in:
parent
ecd5daeaa0
commit
64bbc09e99
2 changed files with 35 additions and 22 deletions
|
|
@ -21,8 +21,8 @@ import {
|
||||||
useListCenter,
|
useListCenter,
|
||||||
useScrape,
|
useScrape,
|
||||||
} from "@/hooks/useProviderScrape";
|
} from "@/hooks/useProviderScrape";
|
||||||
|
import { playerStatus } from "@/stores/player/slices/source";
|
||||||
import { WarningPart } from "../util/WarningPart";
|
import { usePlayerStore } from "@/stores/player/store";
|
||||||
|
|
||||||
export interface ScrapingProps {
|
export interface ScrapingProps {
|
||||||
media: ScrapeMedia;
|
media: ScrapeMedia;
|
||||||
|
|
@ -40,10 +40,12 @@ export function ScrapingPart(props: ScrapingProps) {
|
||||||
useScrape();
|
useScrape();
|
||||||
const isMounted = useMountedState();
|
const isMounted = useMountedState();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const setStatus = usePlayerStore((s) => s.setStatus);
|
||||||
|
const addFailedSource = usePlayerStore((s) => s.addFailedSource);
|
||||||
|
const sourceId = usePlayerStore((s) => s.sourceId);
|
||||||
|
|
||||||
const containerRef = useRef<HTMLDivElement | null>(null);
|
const containerRef = useRef<HTMLDivElement | null>(null);
|
||||||
const listRef = useRef<HTMLDivElement | null>(null);
|
const listRef = useRef<HTMLDivElement | null>(null);
|
||||||
const [failedStartScrape, setFailedStartScrape] = useState<boolean>(false);
|
|
||||||
const renderedOnce = useListCenter(
|
const renderedOnce = useListCenter(
|
||||||
containerRef,
|
containerRef,
|
||||||
listRef,
|
listRef,
|
||||||
|
|
@ -86,8 +88,36 @@ export function ScrapingPart(props: ScrapingProps) {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
props.onGetStream?.(output);
|
props.onGetStream?.(output);
|
||||||
})().catch(() => setFailedStartScrape(true));
|
})().catch((error) => {
|
||||||
}, [startScraping, resumeScraping, props, report, isMounted]);
|
if (!isMounted()) return;
|
||||||
|
// Treat scraping failure as fatal error
|
||||||
|
// Mark current source as failed if we have one
|
||||||
|
if (sourceId) {
|
||||||
|
addFailedSource(sourceId);
|
||||||
|
} else if (currentSource) {
|
||||||
|
addFailedSource(currentSource);
|
||||||
|
}
|
||||||
|
// Set error and status to trigger PlaybackErrorPart
|
||||||
|
usePlayerStore.setState((s) => {
|
||||||
|
s.interface.error = {
|
||||||
|
errorName: "ScrapingError",
|
||||||
|
message: error?.message || "Failed to start scraping",
|
||||||
|
type: "global",
|
||||||
|
};
|
||||||
|
s.status = playerStatus.PLAYBACK_ERROR;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}, [
|
||||||
|
startScraping,
|
||||||
|
resumeScraping,
|
||||||
|
props,
|
||||||
|
report,
|
||||||
|
isMounted,
|
||||||
|
setStatus,
|
||||||
|
addFailedSource,
|
||||||
|
sourceId,
|
||||||
|
currentSource,
|
||||||
|
]);
|
||||||
|
|
||||||
let currentProviderIndex = sourceOrder.findIndex(
|
let currentProviderIndex = sourceOrder.findIndex(
|
||||||
(s) => s.id === currentSource || s.children.includes(currentSource ?? ""),
|
(s) => s.id === currentSource || s.children.includes(currentSource ?? ""),
|
||||||
|
|
@ -95,9 +125,6 @@ export function ScrapingPart(props: ScrapingProps) {
|
||||||
if (currentProviderIndex === -1)
|
if (currentProviderIndex === -1)
|
||||||
currentProviderIndex = sourceOrder.length - 1;
|
currentProviderIndex = sourceOrder.length - 1;
|
||||||
|
|
||||||
if (failedStartScrape)
|
|
||||||
return <WarningPart>{t("player.scraping.items.failure")}</WarningPart>;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="h-full w-full relative dir-neutral:origin-top-left flex"
|
className="h-full w-full relative dir-neutral:origin-top-left flex"
|
||||||
|
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
import { Icon, Icons } from "@/components/Icon";
|
|
||||||
import { BlurEllipsis } from "@/pages/layouts/SubPageLayout";
|
|
||||||
|
|
||||||
export function WarningPart(props: { children: React.ReactNode }) {
|
|
||||||
return (
|
|
||||||
<div className="flex flex-col justify-center items-center h-screen text-center font-medium">
|
|
||||||
<BlurEllipsis />
|
|
||||||
<Icon className="text-type-danger text-2xl" icon={Icons.WARNING} />
|
|
||||||
<div className="max-w-[19rem] mt-3 mb-12 text-type-secondary">
|
|
||||||
{props.children}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Loading…
Reference in a new issue