From 456048a92cbf021cd0e66c677c6dfc51e3b4ad81 Mon Sep 17 00:00:00 2001 From: Fredrik Burmester Date: Sun, 29 Sep 2024 08:05:22 +0200 Subject: [PATCH] wip --- app/_layout.tsx | 1 + components/DownloadItem.tsx | 12 +- components/downloads/ActiveDownload.tsx | 3 +- components/settings/SettingToggles.tsx | 262 +++++++++++++++--------- hooks/useRemuxHlsToMp4.ts | 12 +- providers/DownloadProvider.tsx | 1 + utils/atoms/settings.ts | 4 + 7 files changed, 191 insertions(+), 104 deletions(-) diff --git a/app/_layout.tsx b/app/_layout.tsx index df850e65..1ed76bf2 100644 --- a/app/_layout.tsx +++ b/app/_layout.tsx @@ -168,6 +168,7 @@ function Layout() { color: "white", }, }} + closeButton /> diff --git a/components/DownloadItem.tsx b/components/DownloadItem.tsx index 99bfe8a6..83b74da7 100644 --- a/components/DownloadItem.tsx +++ b/components/DownloadItem.tsx @@ -150,10 +150,7 @@ export const DownloadItem: React.FC = ({ item, ...props }) => { if (!url) throw new Error("No url"); - if ( - settings?.optimizedVersionsServerUrl && - settings.optimizedVersionsServerUrl.length > 0 - ) { + if (settings?.downloadMethod === "optimized") { return await startBackgroundDownload(url, item); } else { return await startRemuxing(url); @@ -304,6 +301,13 @@ export const DownloadItem: React.FC = ({ item, ...props }) => { > Download + + {settings?.downloadMethod === "optimized" ? ( + Using optimized server + ) : ( + Using default method + )} + diff --git a/components/downloads/ActiveDownload.tsx b/components/downloads/ActiveDownload.tsx index 8ce525cc..a19aa61a 100644 --- a/components/downloads/ActiveDownload.tsx +++ b/components/downloads/ActiveDownload.tsx @@ -22,7 +22,7 @@ export const ActiveDownload: React.FC = ({ ...props }) => { mutationFn: async () => { if (!process) throw new Error("No active download"); - if (settings?.optimizedVersionsServerUrl) { + if (settings?.downloadMethod === "optimized") { await axios.delete( settings?.optimizedVersionsServerUrl + "cancel-job/" + process.id, { @@ -45,6 +45,7 @@ export const ActiveDownload: React.FC = ({ ...props }) => { onError: (e) => { console.log(e); toast.error("Failed to cancel download"); + clearProcess(); }, }); diff --git a/components/settings/SettingToggles.tsx b/components/settings/SettingToggles.tsx index 812980c4..b0b0b557 100644 --- a/components/settings/SettingToggles.tsx +++ b/components/settings/SettingToggles.tsx @@ -23,6 +23,7 @@ import { useState } from "react"; import { Button } from "../Button"; import { MediaToggles } from "./MediaToggles"; import * as ScreenOrientation from "expo-screen-orientation"; +import { opacity } from "react-native-reanimated/lib/typescript/reanimated2/Colors"; interface Props extends ViewProps {} @@ -458,112 +459,177 @@ export const SettingToggles: React.FC = ({ ...props }) => { - Optimized versions + Downloads - - - Optimized versions server + + + Download method - Set the URL for the optimized versions server for downloads. + Choose the download method to use. Optimized requires the + optimized server. - - setOptimizedVersionsServerUrl(text)} - /> - - - - {settings.optimizedVersionsServerUrl && ( - - {settings.optimizedVersionsServerUrl} - - )} + Methods + { + updateSettings({ downloadMethod: "remux" }); + queryClient.invalidateQueries({ queryKey: ["search"] }); + }} + > + Default + + { + updateSettings({ downloadMethod: "optimized" }); + queryClient.invalidateQueries({ queryKey: ["search"] }); + }} + > + Optimized + + + - - - - - Optimized versions auth header - - - The auth header for the optimized versions server. - - - - setOptimizedVersionsAuthHeader(text)} - className="w-full" - /> - - - - {settings.optimizedVersionsAuthHeader && ( - - - {settings.optimizedVersionsAuthHeader} + + + + Optimized versions server + + Set the URL for the optimized versions server for downloads. - )} - + + setOptimizedVersionsServerUrl(text)} + /> + + + + {settings.optimizedVersionsServerUrl && ( + + {settings.optimizedVersionsServerUrl} + + )} + + + + + + Optimized versions auth header + + + The auth header for the optimized versions server. + + + + setOptimizedVersionsAuthHeader(text)} + className="w-full" + /> + + + + {settings.optimizedVersionsAuthHeader && ( + + + {settings.optimizedVersionsAuthHeader} + + + )} + + diff --git a/hooks/useRemuxHlsToMp4.ts b/hooks/useRemuxHlsToMp4.ts index e4b1b179..bcecd86b 100644 --- a/hooks/useRemuxHlsToMp4.ts +++ b/hooks/useRemuxHlsToMp4.ts @@ -8,6 +8,7 @@ import { writeToLog } from "@/utils/log"; import { useQueryClient } from "@tanstack/react-query"; import { toast } from "sonner-native"; import { useDownload } from "@/providers/DownloadProvider"; +import { useRouter } from "expo-router"; /** * Custom hook for remuxing HLS to MP4 using FFmpeg. @@ -20,6 +21,7 @@ export const useRemuxHlsToMp4 = (item: BaseItemDto) => { const queryClient = useQueryClient(); const { process, updateProcess, clearProcess, saveDownloadedItemInfo } = useDownload(); + const router = useRouter(); if (!item.Id || !item.Name) { writeToLog("ERROR", "useRemuxHlsToMp4 ~ missing arguments"); @@ -32,7 +34,15 @@ export const useRemuxHlsToMp4 = (item: BaseItemDto) => { async (url: string) => { if (!item.Id) throw new Error("Item must have an Id"); - toast.success("Download started"); + toast.success(`Download started for ${item.Name}`, { + action: { + label: "Go to download", + onClick: () => { + router.push("/downloads"); + toast.dismiss(); + }, + }, + }); const command = `-y -loglevel quiet -thread_queue_size 512 -protocol_whitelist file,http,https,tcp,tls,crypto -multiple_requests 1 -tcp_nodelay 1 -fflags +genpts -i ${url} -c copy -bufsize 50M -max_muxing_queue_size 4096 ${output}`; diff --git a/providers/DownloadProvider.tsx b/providers/DownloadProvider.tsx index 2fdc38a2..4c858ca7 100644 --- a/providers/DownloadProvider.tsx +++ b/providers/DownloadProvider.tsx @@ -264,6 +264,7 @@ function useDownloadProvider() { label: "Go to download", onClick: () => { router.push("/downloads"); + toast.dismiss(); }, }, }); diff --git a/utils/atoms/settings.ts b/utils/atoms/settings.ts index 2e8ac5a0..d6aabd59 100644 --- a/utils/atoms/settings.ts +++ b/utils/atoms/settings.ts @@ -74,6 +74,7 @@ type Settings = { rewindSkipTime: number; optimizedVersionsServerUrl?: string | null; optimizedVersionsAuthHeader?: string | null; + downloadMethod?: "optimized" | "remux"; }; /** * @@ -108,6 +109,9 @@ const loadSettings = async (): Promise => { defaultVideoOrientation: ScreenOrientation.OrientationLock.DEFAULT, forwardSkipTime: 30, rewindSkipTime: 10, + optimizedVersionsServerUrl: null, + optimizedVersionsAuthHeader: null, + downloadMethod: "remux", }; try {