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], [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>,
@@ -186,8 +190,9 @@ export const useDownloadManager = () => {
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"); console.error("Cache directory is unavailable");
return; return;
@@ -214,7 +219,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 +231,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 +297,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 +399,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,

View File

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

590
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff