mirror of
https://github.com/movie-web/native-app.git
synced 2025-09-13 10:23:24 +00:00
feat: link context menu and downloadmanager
This commit is contained in:
@@ -17,6 +17,7 @@ export default function VideoPlayerWrapper() {
|
||||
const data = params.data
|
||||
? (JSON.parse(params.data as string) as ItemData)
|
||||
: null;
|
||||
const download = params.download === "true";
|
||||
|
||||
if (!data) return router.back();
|
||||
|
||||
@@ -26,6 +27,10 @@ export default function VideoPlayerWrapper() {
|
||||
return <VideoPlayer />;
|
||||
}
|
||||
|
||||
if (download) {
|
||||
return <ScraperProcess data={data} download />;
|
||||
}
|
||||
|
||||
if (playerStatus === PlayerStatus.SCRAPING) {
|
||||
return <ScraperProcess data={data} />;
|
||||
}
|
||||
|
@@ -5,7 +5,6 @@ import ContextMenu from "react-native-context-menu-view";
|
||||
import { useRouter } from "expo-router";
|
||||
import { Image, Text, View } from "tamagui";
|
||||
|
||||
import { useDownloadManager } from "~/hooks/DownloadManagerContext";
|
||||
import { usePlayerStore } from "~/stores/player/store";
|
||||
|
||||
export interface ItemData {
|
||||
@@ -19,7 +18,6 @@ export interface ItemData {
|
||||
export default function Item({ data }: { data: ItemData }) {
|
||||
const resetVideo = usePlayerStore((state) => state.resetVideo);
|
||||
const router = useRouter();
|
||||
const { startDownload } = useDownloadManager();
|
||||
|
||||
const { title, type, year, posterUrl } = data;
|
||||
|
||||
@@ -40,11 +38,12 @@ export default function Item({ data }: { data: ItemData }) {
|
||||
const onContextMenuPress = (
|
||||
e: NativeSyntheticEvent<ContextMenuOnPressNativeEvent>,
|
||||
) => {
|
||||
console.log(e.nativeEvent.name);
|
||||
startDownload(
|
||||
"https://samplelib.com/lib/preview/mp4/sample-5s.mp4",
|
||||
"mp4",
|
||||
).catch(console.error);
|
||||
if (e.nativeEvent.name === "Download") {
|
||||
router.push({
|
||||
pathname: "/videoPlayer",
|
||||
params: { data: JSON.stringify(data), download: "true" },
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
|
@@ -5,10 +5,14 @@ import { useRouter } from "expo-router";
|
||||
import { View } from "tamagui";
|
||||
|
||||
import type { HlsBasedStream } from "@movie-web/provider-utils";
|
||||
import { extractTracksFromHLS } from "@movie-web/provider-utils";
|
||||
import {
|
||||
extractTracksFromHLS,
|
||||
findHighestQuality,
|
||||
} from "@movie-web/provider-utils";
|
||||
|
||||
import type { ItemData } from "../item/item";
|
||||
import type { AudioTrack } from "./AudioTrackSelector";
|
||||
import { useDownloadManager } from "~/hooks/DownloadManagerContext";
|
||||
import { useMeta } from "~/hooks/player/useMeta";
|
||||
import { useScrape } from "~/hooks/player/useSourceScrape";
|
||||
import { constructFullUrl } from "~/lib/url";
|
||||
@@ -19,10 +23,12 @@ import { ScrapeCard, ScrapeItem } from "./ScrapeCard";
|
||||
|
||||
interface ScraperProcessProps {
|
||||
data: ItemData;
|
||||
download?: boolean;
|
||||
}
|
||||
|
||||
export const ScraperProcess = ({ data }: ScraperProcessProps) => {
|
||||
export const ScraperProcess = ({ data, download }: ScraperProcessProps) => {
|
||||
const router = useRouter();
|
||||
const { startDownload } = useDownloadManager();
|
||||
|
||||
const scrollViewRef = useRef<ScrollView>(null);
|
||||
|
||||
@@ -43,6 +49,17 @@ export const ScraperProcess = ({ data }: ScraperProcessProps) => {
|
||||
const streamResult = await startScraping(convertMetaToScrapeMedia(meta));
|
||||
|
||||
if (!streamResult) return router.back();
|
||||
if (download) {
|
||||
if (streamResult.stream.type === "file") {
|
||||
const highestQuality = findHighestQuality(streamResult.stream);
|
||||
const url = highestQuality
|
||||
? streamResult.stream.qualities[highestQuality]?.url
|
||||
: null;
|
||||
if (!url) return;
|
||||
startDownload(url, "mp4").catch(console.error);
|
||||
}
|
||||
return router.back();
|
||||
}
|
||||
setStream(streamResult.stream);
|
||||
|
||||
if (streamResult.stream.type === "hls") {
|
||||
@@ -88,12 +105,14 @@ export const ScraperProcess = ({ data }: ScraperProcessProps) => {
|
||||
}, [
|
||||
convertMovieIdToMeta,
|
||||
data,
|
||||
download,
|
||||
router,
|
||||
setAudioTracks,
|
||||
setHlsTracks,
|
||||
setPlayerStatus,
|
||||
setSourceId,
|
||||
setStream,
|
||||
startDownload,
|
||||
startScraping,
|
||||
]);
|
||||
|
||||
|
Reference in New Issue
Block a user