mirror of
https://github.com/movie-web/native-app.git
synced 2025-09-13 10:33:26 +00:00
Compare commits
8 Commits
f6a265f17b
...
daba32627b
Author | SHA1 | Date | |
---|---|---|---|
|
daba32627b | ||
|
8d1ec8f1dc | ||
|
e83054c1ca | ||
|
93111ecdcd | ||
|
17d907335f | ||
|
030dca29f9 | ||
|
2b1aa407d4 | ||
|
5b80273dfb |
@@ -41,7 +41,7 @@ export default function Page() {
|
||||
title: download?.media.title ?? "Downloads",
|
||||
}}
|
||||
/>
|
||||
<YStack gap="$3">
|
||||
<YStack gap="$4">
|
||||
{download?.downloads.map((download) => {
|
||||
return (
|
||||
<DownloadItem
|
||||
|
@@ -37,7 +37,7 @@ const formatBytes = (bytes: number, decimals = 2) => {
|
||||
const dm = decimals < 0 ? 0 : decimals;
|
||||
const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i];
|
||||
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
|
||||
};
|
||||
|
||||
export function DownloadItem(props: DownloadItemProps) {
|
||||
@@ -100,14 +100,19 @@ export function DownloadItem(props: DownloadItemProps) {
|
||||
height="100%"
|
||||
/>
|
||||
</View>
|
||||
<YStack gap="$2">
|
||||
<XStack gap="$6" maxWidth="65%">
|
||||
<Text fontWeight="$bold" ellipse flexGrow={1}>
|
||||
<YStack gap="$2" flex={1}>
|
||||
<XStack justifyContent="space-between" alignItems="center">
|
||||
<Text
|
||||
fontWeight="$bold"
|
||||
numberOfLines={1}
|
||||
ellipsizeMode="tail"
|
||||
flex={1}
|
||||
>
|
||||
{props.item.media.type === "show" &&
|
||||
mapSeasonAndEpisodeNumberToText(
|
||||
`${mapSeasonAndEpisodeNumberToText(
|
||||
props.item.media.season.number,
|
||||
props.item.media.episode.number,
|
||||
) + " "}
|
||||
)} `}
|
||||
{props.item.media.title}
|
||||
</Text>
|
||||
{props.item.type !== "hls" && (
|
||||
|
@@ -43,7 +43,7 @@ export default function ScreenLayout({
|
||||
start={[0, 0]}
|
||||
end={[1, 1]}
|
||||
flexGrow={1}
|
||||
paddingTop={showHeader ? insets.top : insets.top + 50}
|
||||
paddingTop={showHeader ? insets.top + 16 : insets.top + 50}
|
||||
>
|
||||
{showHeader && <Header />}
|
||||
<ScrollView
|
||||
|
@@ -28,11 +28,9 @@ export const BottomControls = () => {
|
||||
const { currentTime, remainingTime } = useMemo(() => {
|
||||
if (status?.isLoaded) {
|
||||
const current = mapMillisecondsToTime(status.positionMillis ?? 0);
|
||||
const remaining =
|
||||
"-" +
|
||||
mapMillisecondsToTime(
|
||||
const remaining = `-${mapMillisecondsToTime(
|
||||
(status.durationMillis ?? 0) - (status.positionMillis ?? 0),
|
||||
);
|
||||
)}`;
|
||||
return { currentTime: current, remainingTime: remaining };
|
||||
} else {
|
||||
return { currentTime: "", remainingTime: "" };
|
||||
|
@@ -124,11 +124,12 @@ export const useDownloadManager = () => {
|
||||
[setDownloads],
|
||||
);
|
||||
|
||||
const saveFileToMediaLibraryAndDeleteOriginal = async (
|
||||
fileUri: string,
|
||||
download: Download,
|
||||
): Promise<Asset | void> => {
|
||||
console.log("Saving file to media library and deleting original", fileUri);
|
||||
const saveFileToMediaLibraryAndDeleteOriginal = useCallback(
|
||||
async (fileUri: string, download: Download): Promise<Asset | void> => {
|
||||
console.log(
|
||||
"Saving file to media library and deleting original",
|
||||
fileUri,
|
||||
);
|
||||
try {
|
||||
updateDownloadItem(download.id, { status: "importing" });
|
||||
|
||||
@@ -151,9 +152,12 @@ export const useDownloadManager = () => {
|
||||
burntOptions: { preset: "error" },
|
||||
});
|
||||
}
|
||||
};
|
||||
},
|
||||
[updateDownloadItem, showToast],
|
||||
);
|
||||
|
||||
const downloadMP4 = async (
|
||||
const downloadMP4 = useCallback(
|
||||
async (
|
||||
url: string,
|
||||
downloadItem: Download,
|
||||
headers: Record<string, string>,
|
||||
@@ -184,13 +188,13 @@ export const useDownloadManager = () => {
|
||||
lastTimestamp = currentTime;
|
||||
};
|
||||
|
||||
const fileUri = `${FileSystem.cacheDirectory}movie-web${url.split("/").pop()}`;
|
||||
const fileUri = `${FileSystem.cacheDirectory}movie-web/${url.split("/").pop()}`;
|
||||
if (
|
||||
!(await FileSystem.getInfoAsync(`${FileSystem.cacheDirectory}movie-web`))
|
||||
.exists
|
||||
!(
|
||||
await FileSystem.getInfoAsync(`${FileSystem.cacheDirectory}movie-web`)
|
||||
).exists
|
||||
) {
|
||||
console.error("Cache directory is unavailable");
|
||||
return;
|
||||
await ensureDirExists(`${FileSystem.cacheDirectory}movie-web`);
|
||||
}
|
||||
|
||||
const downloadResumable = FileSystem.createDownloadResumable(
|
||||
@@ -214,7 +218,9 @@ export const useDownloadManager = () => {
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
};
|
||||
},
|
||||
[updateDownloadItem, saveFileToMediaLibraryAndDeleteOriginal],
|
||||
);
|
||||
|
||||
const cleanupDownload = useCallback(
|
||||
async (segmentDir: string, download: Download) => {
|
||||
@@ -224,7 +230,8 @@ export const useDownloadManager = () => {
|
||||
[removeDownload],
|
||||
);
|
||||
|
||||
const downloadHLS = async (
|
||||
const downloadHLS = useCallback(
|
||||
async (
|
||||
url: string,
|
||||
download: Download,
|
||||
headers: Record<string, string>,
|
||||
@@ -289,11 +296,23 @@ export const useDownloadManager = () => {
|
||||
localSegmentPaths,
|
||||
`${FileSystem.cacheDirectory}movie-web/output.mp4`,
|
||||
);
|
||||
const asset = await saveFileToMediaLibraryAndDeleteOriginal(uri, download);
|
||||
const asset = await saveFileToMediaLibraryAndDeleteOriginal(
|
||||
uri,
|
||||
download,
|
||||
);
|
||||
return asset;
|
||||
};
|
||||
},
|
||||
[
|
||||
getCancellationFlag,
|
||||
updateDownloadItem,
|
||||
saveFileToMediaLibraryAndDeleteOriginal,
|
||||
removeDownload,
|
||||
cleanupDownload,
|
||||
],
|
||||
);
|
||||
|
||||
const startDownload = async (
|
||||
const startDownload = useCallback(
|
||||
async (
|
||||
url: string,
|
||||
type: "mp4" | "hls",
|
||||
media: ScrapeMedia,
|
||||
@@ -379,7 +398,9 @@ export const useDownloadManager = () => {
|
||||
const asset = await downloadHLS(url, newDownload, headers ?? {});
|
||||
return asset;
|
||||
}
|
||||
};
|
||||
},
|
||||
[downloads, showToast, setDownloads, downloadMP4, downloadHLS],
|
||||
);
|
||||
|
||||
const downloadSegment = async (
|
||||
segmentUrl: string,
|
||||
|
@@ -29,7 +29,7 @@
|
||||
},
|
||||
"prettier": "@movie-web/prettier-config",
|
||||
"dependencies": {
|
||||
"@movie-web/providers": "^2.2.9",
|
||||
"@movie-web/providers": "^2.3.0",
|
||||
"parse-hls": "^1.0.7",
|
||||
"srt-webvtt": "^2.0.0",
|
||||
"tmdb-ts": "^1.6.1"
|
||||
|
@@ -228,7 +228,7 @@ export async function findHLSQuality(
|
||||
const chosenQuality = sortedStreams[highest ? 0 : sortedStreams.length - 1];
|
||||
if (!chosenQuality) return null;
|
||||
|
||||
return chosenQuality.uri;
|
||||
return constructFullUrl(playlistUrl, chosenQuality.uri);
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
|
590
pnpm-lock.yaml
generated
590
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user