From 96a44e5cb22b7db86cdc4e358717797278f5e288 Mon Sep 17 00:00:00 2001 From: Sneed Group Holder Date: Mon, 28 Oct 2024 11:18:33 -0500 Subject: [PATCH] fixes --- index.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 9e7bccc..b1a7e8a 100644 --- a/index.js +++ b/index.js @@ -53,10 +53,10 @@ app.get('/download', (req, res) => { } // Set the output file path - const outputPath = path.join(__dirname, '/tmp/downloads', '%(title)s.%(ext)s'); + var outputPath = path.join('/tmp/downloads', '%(title)s.%(ext)s'); // Create /tmp/downloads directory if it doesn't exist - fs.mkdirSync(path.join(__dirname, '/tmp/downloads'), { recursive: true }); + fs.mkdirSync(path.join('/tmp/downloads'), { recursive: true }); // Use yt-dlp to download the video exec(`yt-dlp -o "${outputPath}" "${videoUrl}"`, (error, stdout, stderr) => { @@ -64,15 +64,12 @@ app.get('/download', (req, res) => { return res.status(500).json({ error: 'An error occurred while downloading the video.', details: stderr }); } - // Parse the output to get the file name - const filename = stdout.split('\n').find(line => line.includes('Destination'))?.split(' ')[1]; - if (!filename) { return res.status(500).json({ error: 'Downloaded file not found.' }); } // Full path of the downloaded file - const downloadedFilePath = path.join(__dirname, '/tmp/downloads', filename); + const downloadedFilePath = outputPath; // Check if the file exists and send it if (fs.existsSync(downloadedFilePath)) {