diff --git a/apps/expo/src/app/(tabs)/downloads.tsx b/apps/expo/src/app/(tabs)/downloads.tsx index 3465b52..e8a2295 100644 --- a/apps/expo/src/app/(tabs)/downloads.tsx +++ b/apps/expo/src/app/(tabs)/downloads.tsx @@ -5,6 +5,8 @@ import { useRouter } from "expo-router"; import { MaterialCommunityIcons } from "@expo/vector-icons"; import { useTheme, YStack } from "tamagui"; +import type { ScrapeMedia } from "@movie-web/provider-utils"; + import { DownloadItem } from "~/components/DownloadItem"; import ScreenLayout from "~/components/layout/ScreenLayout"; import { MWButton } from "~/components/ui/Button"; @@ -27,9 +29,24 @@ const DownloadsScreen: React.FC = () => { }); }; + const exampleShowMedia: ScrapeMedia = { + type: "show", + title: "Example Show Title", + releaseYear: 2022, + imdbId: "tt1234567", + tmdbId: "12345", + season: { + number: 1, + tmdbId: "54321", + }, + episode: { + number: 3, + tmdbId: "98765", + }, + }; return ( - + { await startDownload( "https://samplelib.com/lib/preview/mp4/sample-5s.mp4", "mp4", + exampleShowMedia, ).catch(console.error); }} > @@ -63,6 +81,7 @@ const DownloadsScreen: React.FC = () => { await startDownload( "http://sample.vodobox.com/skate_phantom_flex_4k/skate_phantom_flex_4k.m3u8", "hls", + exampleShowMedia, ).catch(console.error); }} > diff --git a/apps/expo/src/components/player/DownloadButton.tsx b/apps/expo/src/components/player/DownloadButton.tsx index e1a8beb..46605a1 100644 --- a/apps/expo/src/components/player/DownloadButton.tsx +++ b/apps/expo/src/components/player/DownloadButton.tsx @@ -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 diff --git a/apps/expo/src/components/player/ScraperProcess.tsx b/apps/expo/src/components/player/ScraperProcess.tsx index f8debcf..a63ecc6 100644 --- a/apps/expo/src/components/player/ScraperProcess.tsx +++ b/apps/expo/src/components/player/ScraperProcess.tsx @@ -42,7 +42,7 @@ export const ScraperProcess = ({ const scrollViewRef = useRef(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, diff --git a/apps/expo/src/hooks/DownloadManagerContext.tsx b/apps/expo/src/hooks/DownloadManagerContext.tsx index 06d4733..338d053 100644 --- a/apps/expo/src/hooks/DownloadManagerContext.tsx +++ b/apps/expo/src/hooks/DownloadManagerContext.tsx @@ -6,6 +6,7 @@ import * as MediaLibrary from "expo-media-library"; import VideoManager from "@salihgun/react-native-video-processor"; import { useToastController } from "@tamagui/toast"; +import type { ScrapeMedia } from "@movie-web/provider-utils"; import { extractSegmentsFromHLS } from "@movie-web/provider-utils"; import { useDownloadHistoryStore } from "~/stores/settings"; @@ -23,12 +24,18 @@ export interface DownloadItem { statusText?: string; asset?: Asset; isHLS?: boolean; + media: ScrapeMedia; downloadResumable?: FileSystem.DownloadResumable; } interface DownloadManagerContextType { downloads: DownloadItem[]; - startDownload: (url: string, type: "mp4" | "hls") => Promise; + startDownload: ( + url: string, + type: "mp4" | "hls", + media: ScrapeMedia, + headers?: Record, + ) => Promise; removeDownload: (id: string) => void; cancelDownload: (id: string) => Promise; } @@ -94,6 +101,7 @@ export const DownloadManagerProvider: React.FC<{ children: ReactNode }> = ({ const startDownload = async ( url: string, type: "mp4" | "hls", + media: ScrapeMedia, headers?: Record, ): Promise => { toastController.show("Download started", { @@ -113,6 +121,7 @@ export const DownloadManagerProvider: React.FC<{ children: ReactNode }> = ({ url, isFinished: false, isHLS: type === "hls", + media, }; setDownloads((currentDownloads) => [newDownload, ...currentDownloads]); diff --git a/apps/expo/src/hooks/player/useMeta.ts b/apps/expo/src/hooks/player/useMeta.ts index 8c3c78d..ccb9388 100644 --- a/apps/expo/src/hooks/player/useMeta.ts +++ b/apps/expo/src/hooks/player/useMeta.ts @@ -9,7 +9,7 @@ export const useMeta = () => { const meta = usePlayerStore((state) => state.meta); const setMeta = usePlayerStore((state) => state.setMeta); - const convertMovieIdToMeta = useCallback( + const convertIdToMeta = useCallback( async (id: string, type: "movie" | "tv") => { const media = await fetchMediaDetails(id, type); if (!media) return; @@ -54,5 +54,5 @@ export const useMeta = () => { [meta?.episode?.number, meta?.season?.number, setMeta], ); - return { convertMovieIdToMeta }; + return { convertIdToMeta }; };