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