1
0
Fork 0
mirror of https://github.com/sussy-code/smov.git synced 2024-12-20 14:37:43 +01:00

Fix some thumbnail scraping setting logic

Co-authored-by: Jip Frijlink <JipFr@users.noreply.github.com>
This commit is contained in:
mrjvs 2024-01-18 19:29:58 +01:00
parent dc95bd7455
commit b3222b130f
4 changed files with 13 additions and 11 deletions

View file

@ -11,7 +11,6 @@ import { VideoClickTarget } from "@/components/player/internals/VideoClickTarget
import { VideoContainer } from "@/components/player/internals/VideoContainer";
import { PlayerHoverState } from "@/stores/player/slices/interface";
import { usePlayerStore } from "@/stores/player/store";
import { usePreferencesStore } from "@/stores/preferences";
export interface PlayerProps {
children?: ReactNode;
@ -79,7 +78,6 @@ function BaseContainer(props: { children?: ReactNode }) {
export function Container(props: PlayerProps) {
const propRef = useRef(props.onLoad);
const enableThumbnails = usePreferencesStore((s) => s.enableThumbnails);
useEffect(() => {
propRef.current?.();
}, []);
@ -88,7 +86,7 @@ export function Container(props: PlayerProps) {
<div className="relative">
<BaseContainer>
<MetaReporter />
{enableThumbnails ? <ThumbnailScraper /> : null}
<ThumbnailScraper />
<CastingInternal />
<VideoContainer />
<ProgressSaver />

View file

@ -5,6 +5,7 @@ import {
} from "@movie-web/providers";
import { useAsyncFn } from "react-use";
import { isExtensionActiveCached } from "@/backend/extension/messaging";
import { prepareStream } from "@/backend/extension/streams";
import {
connectServerSideEvents,
@ -72,7 +73,7 @@ export function useEmbedScraping(
report([
scrapeSourceOutputToProviderMetric(meta, sourceId, null, "success", null),
]);
await prepareStream(result.stream[0]);
if (isExtensionActiveCached()) await prepareStream(result.stream[0]);
setSourceId(sourceId);
setCaption(null);
setSource(
@ -133,7 +134,7 @@ export function useSourceScraping(sourceId: string | null, routerId: string) {
]);
if (result.stream) {
await prepareStream(result.stream[0]);
if (isExtensionActiveCached()) await prepareStream(result.stream[0]);
setCaption(null);
setSource(
convertRunoutputToSource({ stream: result.stream[0] }),
@ -190,7 +191,7 @@ export function useSourceScraping(sourceId: string | null, routerId: string) {
]);
setSourceId(sourceId);
setCaption(null);
await prepareStream(embedResult.stream[0]);
if (isExtensionActiveCached()) await prepareStream(embedResult.stream[0]);
setSource(
convertRunoutputToSource({ stream: embedResult.stream[0] }),
convertProviderCaption(embedResult.stream[0].captions),

View file

@ -5,6 +5,7 @@ import { playerStatus } from "@/stores/player/slices/source";
import { ThumbnailImage } from "@/stores/player/slices/thumbnails";
import { usePlayerStore } from "@/stores/player/store";
import { LoadableSource, selectQuality } from "@/stores/player/utils/qualities";
import { usePreferencesStore } from "@/stores/preferences";
import { processCdnLink } from "@/utils/cdn";
import { isSafari } from "@/utils/detectFeatures";
@ -128,6 +129,7 @@ export function ThumbnailScraper() {
const resetImages = usePlayerStore((s) => s.thumbnails.resetImages);
const meta = usePlayerStore((s) => s.meta);
const source = usePlayerStore((s) => s.source);
const enableThumbnails = usePreferencesStore((s) => s.enableThumbnails);
const workerRef = useRef<ThumnbnailWorker | null>(null);
// object references dont always trigger changes, so we serialize it to detect *any* change
@ -159,8 +161,8 @@ export function ThumbnailScraper() {
// start worker with the stream
useEffect(() => {
startRef.current();
}, [sourceSeralized]);
if (enableThumbnails) startRef.current();
}, [sourceSeralized, enableThumbnails]);
// destroy worker on unmount
useEffect(() => {
@ -183,8 +185,8 @@ export function ThumbnailScraper() {
workerRef.current.destroy();
workerRef.current = null;
}
startRef.current();
}, [serializedMeta, sourceSeralized, status]);
if (enableThumbnails) startRef.current();
}, [serializedMeta, sourceSeralized, status, enableThumbnails]);
return null;
}

View file

@ -171,7 +171,8 @@ export function useScrape() {
conn.on("update", updateEvent);
conn.on("discoverEmbeds", discoverEmbedsEvent);
const sseOutput = await conn.promise();
if (sseOutput) await prepareStream(sseOutput.stream);
if (sseOutput && isExtensionActiveCached())
await prepareStream(sseOutput.stream);
return getResult(sseOutput === "" ? null : sseOutput);
}