mirror of
https://github.com/p-stream/p-stream.git
synced 2026-03-11 17:55:33 +00:00
i dont get it
This commit is contained in:
parent
28527618a9
commit
28dec0bfc7
7 changed files with 561 additions and 525 deletions
|
|
@ -38,7 +38,7 @@
|
||||||
"@ladjs/country-language": "^1.0.3",
|
"@ladjs/country-language": "^1.0.3",
|
||||||
"@marsidev/react-turnstile": "^0.7.2",
|
"@marsidev/react-turnstile": "^0.7.2",
|
||||||
"@noble/hashes": "^1.8.0",
|
"@noble/hashes": "^1.8.0",
|
||||||
"@p-stream/providers": "github:p-stream/providers#production",
|
"@p-stream/providers": "github:p-stream/providers#skip-sources",
|
||||||
"@plasmohq/messaging": "^0.6.2",
|
"@plasmohq/messaging": "^0.6.2",
|
||||||
"@react-spring/web": "^9.7.5",
|
"@react-spring/web": "^9.7.5",
|
||||||
"@scure/bip39": "^1.6.0",
|
"@scure/bip39": "^1.6.0",
|
||||||
|
|
|
||||||
955
pnpm-lock.yaml
955
pnpm-lock.yaml
File diff suppressed because it is too large
Load diff
|
|
@ -14,6 +14,7 @@ export interface ScrapeItemProps {
|
||||||
id?: string;
|
id?: string;
|
||||||
percentage?: number;
|
percentage?: number;
|
||||||
children?: ReactNode;
|
children?: ReactNode;
|
||||||
|
onSkip?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ScrapeCardProps extends ScrapeItemProps {
|
export interface ScrapeCardProps extends ScrapeItemProps {
|
||||||
|
|
@ -40,10 +41,15 @@ export function ScrapeItem(props: ScrapeItemProps) {
|
||||||
const text = statusTextMap[props.status];
|
const text = statusTextMap[props.status];
|
||||||
const status = statusMap[props.status];
|
const status = statusMap[props.status];
|
||||||
|
|
||||||
|
const handleSkip = () => {
|
||||||
|
props.onSkip?.();
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="grid gap-4 grid-cols-[auto,1fr]" data-source-id={props.id}>
|
<div className="grid gap-4 grid-cols-[auto,1fr]" data-source-id={props.id}>
|
||||||
<StatusCircle type={status} percentage={props.percentage ?? 0} />
|
<StatusCircle type={status} percentage={props.percentage ?? 0} />
|
||||||
<div>
|
<div>
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
<p
|
<p
|
||||||
className={
|
className={
|
||||||
status === "loading" ? "text-white" : "text-type-secondary"
|
status === "loading" ? "text-white" : "text-type-secondary"
|
||||||
|
|
@ -51,6 +57,16 @@ export function ScrapeItem(props: ScrapeItemProps) {
|
||||||
>
|
>
|
||||||
{props.name}
|
{props.name}
|
||||||
</p>
|
</p>
|
||||||
|
{props.status === "pending" && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={handleSkip}
|
||||||
|
className="text-[11px] px-2 py-0.5 rounded-full bg-white/10 text-white/70"
|
||||||
|
>
|
||||||
|
Skip
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
<Transition animation="fade" show={!!text}>
|
<Transition animation="fade" show={!!text}>
|
||||||
<p className="text-[15px] mt-1">{text ? t(text) : ""}</p>
|
<p className="text-[15px] mt-1">{text ? t(text) : ""}</p>
|
||||||
</Transition>
|
</Transition>
|
||||||
|
|
|
||||||
|
|
@ -154,6 +154,8 @@ export function useScrape() {
|
||||||
startScrape,
|
startScrape,
|
||||||
} = useBaseScrape();
|
} = useBaseScrape();
|
||||||
|
|
||||||
|
const abortControllerRef = useRef<AbortController | null>(null);
|
||||||
|
|
||||||
const preferredSourceOrder = usePreferencesStore((s) => s.sourceOrder);
|
const preferredSourceOrder = usePreferencesStore((s) => s.sourceOrder);
|
||||||
const enableSourceOrder = usePreferencesStore((s) => s.enableSourceOrder);
|
const enableSourceOrder = usePreferencesStore((s) => s.enableSourceOrder);
|
||||||
const lastSuccessfulSource = usePreferencesStore(
|
const lastSuccessfulSource = usePreferencesStore(
|
||||||
|
|
@ -257,22 +259,63 @@ export function useScrape() {
|
||||||
return getResult(sseOutput === "" ? null : sseOutput);
|
return getResult(sseOutput === "" ? null : sseOutput);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use individual source loops for local scraping
|
||||||
startScrape();
|
startScrape();
|
||||||
const providers = getProviders();
|
const providers = getProviders();
|
||||||
const output = await providers.runAll({
|
|
||||||
|
// Initialize with all sources
|
||||||
|
initEvent({
|
||||||
|
sourceIds: filteredSourceOrder,
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const sourceId of filteredSourceOrder) {
|
||||||
|
// Create new abort controller for each source
|
||||||
|
abortControllerRef.current = new AbortController();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const output = await providers.runSourceWithEmbeds({
|
||||||
|
sourceId,
|
||||||
media,
|
media,
|
||||||
sourceOrder: filteredSourceOrder,
|
|
||||||
embedOrder: filteredEmbedOrder,
|
embedOrder: filteredEmbedOrder,
|
||||||
|
abortSignal: abortControllerRef.current.signal,
|
||||||
|
skipInit: true,
|
||||||
events: {
|
events: {
|
||||||
init: initEvent,
|
init: initEvent,
|
||||||
start: startEvent,
|
start: startEvent,
|
||||||
update: updateEvent,
|
update: updateEvent,
|
||||||
discoverEmbeds: discoverEmbedsEvent,
|
discoverEmbeds: discoverEmbedsEvent,
|
||||||
|
abort: (abortedId: string) => {
|
||||||
|
// Mark as cancelled/failed when aborted
|
||||||
|
updateEvent({
|
||||||
|
id: abortedId,
|
||||||
|
percentage: 100,
|
||||||
|
status: "notfound",
|
||||||
|
reason: "Skipped by user",
|
||||||
|
});
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (output && isExtensionActiveCached())
|
|
||||||
|
// Clear abort controller after completion
|
||||||
|
abortControllerRef.current = null;
|
||||||
|
|
||||||
|
if (output) {
|
||||||
|
if (isExtensionActiveCached()) {
|
||||||
await prepareStream(output.stream);
|
await prepareStream(output.stream);
|
||||||
|
}
|
||||||
return getResult(output);
|
return getResult(output);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// Clear abort controller on error
|
||||||
|
abortControllerRef.current = null;
|
||||||
|
|
||||||
|
// Continue to next source on error
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// No sources found streams
|
||||||
|
return getResult(null);
|
||||||
},
|
},
|
||||||
[
|
[
|
||||||
initEvent,
|
initEvent,
|
||||||
|
|
@ -292,6 +335,13 @@ export function useScrape() {
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const skipCurrentSource = useCallback(() => {
|
||||||
|
if (abortControllerRef.current) {
|
||||||
|
abortControllerRef.current.abort();
|
||||||
|
abortControllerRef.current = null;
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
const resumeScraping = useCallback(
|
const resumeScraping = useCallback(
|
||||||
async (media: ScrapeMedia, startFromSourceId: string) => {
|
async (media: ScrapeMedia, startFromSourceId: string) => {
|
||||||
return startScraping(media, startFromSourceId);
|
return startScraping(media, startFromSourceId);
|
||||||
|
|
@ -302,6 +352,7 @@ export function useScrape() {
|
||||||
return {
|
return {
|
||||||
startScraping,
|
startScraping,
|
||||||
resumeScraping,
|
resumeScraping,
|
||||||
|
skipCurrentSource,
|
||||||
sourceOrder,
|
sourceOrder,
|
||||||
sources,
|
sources,
|
||||||
currentSource,
|
currentSource,
|
||||||
|
|
|
||||||
|
|
@ -36,8 +36,14 @@ export interface ScrapingProps {
|
||||||
|
|
||||||
export function ScrapingPart(props: ScrapingProps) {
|
export function ScrapingPart(props: ScrapingProps) {
|
||||||
const { report } = useReportProviders();
|
const { report } = useReportProviders();
|
||||||
const { startScraping, resumeScraping, sourceOrder, sources, currentSource } =
|
const {
|
||||||
useScrape();
|
startScraping,
|
||||||
|
resumeScraping,
|
||||||
|
skipCurrentSource,
|
||||||
|
sourceOrder,
|
||||||
|
sources,
|
||||||
|
currentSource,
|
||||||
|
} = useScrape();
|
||||||
const isMounted = useMountedState();
|
const isMounted = useMountedState();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
|
@ -134,6 +140,9 @@ export function ScrapingPart(props: ScrapingProps) {
|
||||||
status={source.status}
|
status={source.status}
|
||||||
hasChildren={order.children.length > 0}
|
hasChildren={order.children.length > 0}
|
||||||
percentage={source.percentage}
|
percentage={source.percentage}
|
||||||
|
onSkip={
|
||||||
|
source.status === "pending" ? skipCurrentSource : undefined
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
className={classNames({
|
className={classNames({
|
||||||
|
|
|
||||||
|
|
@ -323,9 +323,8 @@ export const createSourceSlice: MakeSlice<SourceSlice> = (set, get) => ({
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { scrapeExternalSubtitles } = await import(
|
const { scrapeExternalSubtitles } =
|
||||||
"@/utils/externalSubtitles"
|
await import("@/utils/externalSubtitles");
|
||||||
);
|
|
||||||
const externalCaptions = await scrapeExternalSubtitles(store.meta);
|
const externalCaptions = await scrapeExternalSubtitles(store.meta);
|
||||||
|
|
||||||
if (externalCaptions.length > 0) {
|
if (externalCaptions.length > 0) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue