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,
|
||||
useScrape,
|
||||
} from "@/hooks/useProviderScrape";
|
||||
|
||||
import { WarningPart } from "../util/WarningPart";
|
||||
import { playerStatus } from "@/stores/player/slices/source";
|
||||
import { usePlayerStore } from "@/stores/player/store";
|
||||
|
||||
export interface ScrapingProps {
|
||||
media: ScrapeMedia;
|
||||
|
|
@ -40,10 +40,12 @@ export function ScrapingPart(props: ScrapingProps) {
|
|||
useScrape();
|
||||
const isMounted = useMountedState();
|
||||
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 listRef = useRef<HTMLDivElement | null>(null);
|
||||
const [failedStartScrape, setFailedStartScrape] = useState<boolean>(false);
|
||||
const renderedOnce = useListCenter(
|
||||
containerRef,
|
||||
listRef,
|
||||
|
|
@ -86,8 +88,36 @@ export function ScrapingPart(props: ScrapingProps) {
|
|||
),
|
||||
);
|
||||
props.onGetStream?.(output);
|
||||
})().catch(() => setFailedStartScrape(true));
|
||||
}, [startScraping, resumeScraping, props, report, isMounted]);
|
||||
})().catch((error) => {
|
||||
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(
|
||||
(s) => s.id === currentSource || s.children.includes(currentSource ?? ""),
|
||||
|
|
@ -95,9 +125,6 @@ export function ScrapingPart(props: ScrapingProps) {
|
|||
if (currentProviderIndex === -1)
|
||||
currentProviderIndex = sourceOrder.length - 1;
|
||||
|
||||
if (failedStartScrape)
|
||||
return <WarningPart>{t("player.scraping.items.failure")}</WarningPart>;
|
||||
|
||||
return (
|
||||
<div
|
||||
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