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)) {