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