feat: add scrapemedia to downloaditem

This commit is contained in:
Adrian Castro
2024-03-27 10:40:16 +01:00
parent 4cfe7b6bfd
commit 42e6b1fe63
5 changed files with 50 additions and 11 deletions

View File

@@ -4,14 +4,20 @@ import { useTheme } from "tamagui";
import { findHighestQuality } from "@movie-web/provider-utils";
import { useDownloadManager } from "~/hooks/DownloadManagerContext";
import { convertMetaToScrapeMedia } from "~/lib/meta";
import { usePlayerStore } from "~/stores/player/store";
import { MWButton } from "../ui/Button";
import { Controls } from "./Controls";
export const DownloadButton = () => {
const theme = useTheme();
const stream = usePlayerStore((state) => state.interface.currentStream);
const { startDownload } = useDownloadManager();
const stream = usePlayerStore((state) => state.interface.currentStream);
const meta = usePlayerStore((state) => state.meta);
if (!meta) return null;
const scrapeMedia = convertMetaToScrapeMedia(meta);
let url: string | undefined | null = null;
if (stream?.type === "file") {
@@ -36,7 +42,12 @@ export const DownloadButton = () => {
/>
}
onPress={() =>
url && startDownload(url, stream?.type === "hls" ? "hls" : "mp4")
url &&
startDownload(
url,
stream?.type === "hls" ? "hls" : "mp4",
scrapeMedia,
).catch(console.error)
}
>
Download

View File

@@ -42,7 +42,7 @@ export const ScraperProcess = ({
const scrollViewRef = useRef<ScrollView>(null);
const { convertMovieIdToMeta } = useMeta();
const { convertIdToMeta } = useMeta();
const { startScraping, sourceOrder, sources, currentSource } = useScrape();
const setStream = usePlayerStore((state) => state.setCurrentStream);
@@ -59,7 +59,7 @@ export const ScraperProcess = ({
let meta: PlayerMeta | undefined = undefined;
if (!media && data) {
meta = await convertMovieIdToMeta(data.id, data.type);
meta = await convertIdToMeta(data.id, data.type);
if (!meta) return router.back();
}
@@ -75,9 +75,9 @@ export const ScraperProcess = ({
? streamResult.stream.qualities[highestQuality]?.url
: null;
if (!url) return;
startDownload(url, "mp4").catch(console.error);
startDownload(url, "mp4", scrapeMedia).catch(console.error);
} else if (streamResult.stream.type === "hls") {
startDownload(streamResult.stream.playlist, "hls").catch(
startDownload(streamResult.stream.playlist, "hls", scrapeMedia).catch(
console.error,
);
}
@@ -126,7 +126,7 @@ export const ScraperProcess = ({
};
void fetchData();
}, [
convertMovieIdToMeta,
convertIdToMeta,
data,
download,
media,