From 30bf4c3d7a616305e9fbfcaf68348ba92fa0ff2c Mon Sep 17 00:00:00 2001
From: Adrian Castro <22133246+castdrian@users.noreply.github.com>
Date: Thu, 21 Mar 2024 12:06:35 +0100
Subject: [PATCH] feat: download button in player
---
.../src/components/player/BottomControls.tsx | 2 +
.../src/components/player/DownloadButton.tsx | 40 +++++++++++++++++++
2 files changed, 42 insertions(+)
create mode 100644 apps/expo/src/components/player/DownloadButton.tsx
diff --git a/apps/expo/src/components/player/BottomControls.tsx b/apps/expo/src/components/player/BottomControls.tsx
index 8afca83..846f10c 100644
--- a/apps/expo/src/components/player/BottomControls.tsx
+++ b/apps/expo/src/components/player/BottomControls.tsx
@@ -6,6 +6,7 @@ import { usePlayerStore } from "~/stores/player/store";
import { AudioTrackSelector } from "./AudioTrackSelector";
import { CaptionsSelector } from "./CaptionsSelector";
import { Controls } from "./Controls";
+import { DownloadButton } from "./DownloadButton";
import { PlaybackSpeedSelector } from "./PlaybackSpeedSelector";
import { ProgressBar } from "./ProgressBar";
import { SeasonSelector } from "./SeasonEpisodeSelector";
@@ -79,6 +80,7 @@ export const BottomControls = () => {
+
);
diff --git a/apps/expo/src/components/player/DownloadButton.tsx b/apps/expo/src/components/player/DownloadButton.tsx
new file mode 100644
index 0000000..fe0ef9f
--- /dev/null
+++ b/apps/expo/src/components/player/DownloadButton.tsx
@@ -0,0 +1,40 @@
+import { MaterialCommunityIcons } from "@expo/vector-icons";
+import { useTheme } from "tamagui";
+
+import { findHighestQuality } from "@movie-web/provider-utils";
+
+import { useDownloadManager } from "~/hooks/DownloadManagerContext";
+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();
+ if (stream?.type !== "file") return null;
+
+ const highestQuality = findHighestQuality(stream);
+ const url = highestQuality ? stream.qualities[highestQuality]?.url : null;
+ if (!url) return null;
+
+ return (
+ <>
+
+
+ }
+ onPress={() => startDownload(url, "mp4")}
+ >
+ Download
+
+
+ >
+ );
+};