Fix for infinite rerender while scraping 🍻

This commit is contained in:
Jorrin
2024-04-13 20:24:59 +02:00
parent 4a3d363bf2
commit 5b80273dfb
3 changed files with 281 additions and 777 deletions

View File

@@ -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>,
@@ -186,8 +190,9 @@ export const useDownloadManager = () => {
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;
@@ -214,7 +219,9 @@ export const useDownloadManager = () => {
} catch (e) {
console.error(e);
}
};
},
[updateDownloadItem, saveFileToMediaLibraryAndDeleteOriginal],
);
const cleanupDownload = useCallback(
async (segmentDir: string, download: Download) => {
@@ -224,7 +231,8 @@ export const useDownloadManager = () => {
[removeDownload],
);
const downloadHLS = async (
const downloadHLS = useCallback(
async (
url: string,
download: Download,
headers: Record<string, string>,
@@ -289,11 +297,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 +399,9 @@ export const useDownloadManager = () => {
const asset = await downloadHLS(url, newDownload, headers ?? {});
return asset;
}
};
},
[downloads, showToast, setDownloads, downloadMP4, downloadHLS],
);
const downloadSegment = async (
segmentUrl: string,

View File

@@ -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"

590
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff