MediaDownloader Stop Full Crash
Some checks are pending
Test / Test (push) Waiting to run

This commit is contained in:
thororen1234 2025-05-28 15:19:52 -04:00
parent ffbc286b4b
commit 94dc90a773
No known key found for this signature in database

View file

@ -103,12 +103,21 @@ export async function stop(_: IpcMainInvokeEvent) {
} }
async function metadata(options: DownloadOptions) { async function metadata(options: DownloadOptions) {
try {
stdout_global = ""; stdout_global = "";
const metadata = JSON.parse(await ytdlp(["-J", options.url, "--no-warnings"])); const output = await ytdlp(["-J", options.url, "--no-warnings"]);
if (metadata.is_live) throw "Live streams are not supported."; const metadata = JSON.parse(output);
if (metadata.is_live) throw new Error("Live streams are not supported.");
stdout_global = ""; stdout_global = "";
return { videoTitle: `${metadata.title || "video"} (${metadata.id})` }; return { videoTitle: `${metadata.title || "video"} (${metadata.id})` };
} catch (err) {
throw err;
} }
}
function genFormat({ videoTitle }: { videoTitle: string; }, { maxFileSize, format }: DownloadOptions) { function genFormat({ videoTitle }: { videoTitle: string; }, { maxFileSize, format }: DownloadOptions) {
const HAS_LIMIT = !!maxFileSize; const HAS_LIMIT = !!maxFileSize;
const MAX_VIDEO_SIZE = HAS_LIMIT ? maxFileSize * 0.8 : 0; const MAX_VIDEO_SIZE = HAS_LIMIT ? maxFileSize * 0.8 : 0;
@ -161,8 +170,11 @@ async function download({ format, videoTitle }: { format: string; videoTitle: st
: [] : []
: []; : [];
const customArgs = ytdlpArgs?.filter(Boolean) || []; const customArgs = ytdlpArgs?.filter(Boolean) || [];
try {
await ytdlp([url, ...baseArgs, ...remuxArgs, ...customArgs]); await ytdlp([url, ...baseArgs, ...remuxArgs, ...customArgs]);
} catch (err) {
console.error("Error during yt-dlp execution:", err);
}
const file = fs.readdirSync(getdir()).find(f => f.startsWith("download.")); const file = fs.readdirSync(getdir()).find(f => f.startsWith("download."));
if (!file) throw "No video file was found!"; if (!file) throw "No video file was found!";
return { file, videoTitle }; return { file, videoTitle };