feat: hls downloads

This commit is contained in:
Adrian Castro
2024-03-26 19:57:35 +01:00
parent 0566b5ba54
commit 1e704bcdd6
11 changed files with 241 additions and 40 deletions

View File

@@ -12,10 +12,15 @@ export const DownloadButton = () => {
const theme = useTheme();
const stream = usePlayerStore((state) => state.interface.currentStream);
const { startDownload } = useDownloadManager();
if (stream?.type !== "file") return null;
let url: string | undefined | null = null;
if (stream?.type === "file") {
const highestQuality = findHighestQuality(stream);
url = highestQuality ? stream.qualities[highestQuality]?.url : null;
} else if (stream?.type === "hls") {
url = stream.playlist;
}
const highestQuality = findHighestQuality(stream);
const url = highestQuality ? stream.qualities[highestQuality]?.url : null;
if (!url) return null;
return (
@@ -30,7 +35,9 @@ export const DownloadButton = () => {
color={theme.buttonSecondaryText.val}
/>
}
onPress={() => startDownload(url, "mp4")}
onPress={() =>
url && startDownload(url, stream?.type === "hls" ? "hls" : "mp4")
}
>
Download
</MWButton>

View File

@@ -2,7 +2,8 @@ import { useState } from "react";
import { MaterialCommunityIcons, MaterialIcons } from "@expo/vector-icons";
import { useTheme } from "tamagui";
import { constructFullUrl } from "~/lib/url";
import { constructFullUrl } from "@movie-web/provider-utils";
import { usePlayerStore } from "~/stores/player/store";
import { MWButton } from "../ui/Button";
import { Controls } from "./Controls";

View File

@@ -10,6 +10,7 @@ import type {
ScrapeMedia,
} from "@movie-web/provider-utils";
import {
constructFullUrl,
extractTracksFromHLS,
findHighestQuality,
} from "@movie-web/provider-utils";
@@ -21,7 +22,6 @@ import { useDownloadManager } from "~/hooks/DownloadManagerContext";
import { useMeta } from "~/hooks/player/useMeta";
import { useScrape } from "~/hooks/player/useSourceScrape";
import { convertMetaToScrapeMedia } from "~/lib/meta";
import { constructFullUrl } from "~/lib/url";
import { PlayerStatus } from "~/stores/player/slices/interface";
import { usePlayerStore } from "~/stores/player/store";
import { ScrapeCard, ScrapeItem } from "./ScrapeCard";
@@ -76,6 +76,10 @@ export const ScraperProcess = ({
: null;
if (!url) return;
startDownload(url, "mp4").catch(console.error);
} else if (streamResult.stream.type === "hls") {
startDownload(streamResult.stream.playlist, "hls").catch(
console.error,
);
}
return router.back();
}