fixes
This commit is contained in:
parent
3c37b55d5d
commit
96a44e5cb2
1 changed files with 3 additions and 6 deletions
9
index.js
9
index.js
|
@ -53,10 +53,10 @@ app.get('/download', (req, res) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the output file path
|
// 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
|
// 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
|
// Use yt-dlp to download the video
|
||||||
exec(`yt-dlp -o "${outputPath}" "${videoUrl}"`, (error, stdout, stderr) => {
|
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 });
|
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) {
|
if (!filename) {
|
||||||
return res.status(500).json({ error: 'Downloaded file not found.' });
|
return res.status(500).json({ error: 'Downloaded file not found.' });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Full path of the downloaded file
|
// 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
|
// Check if the file exists and send it
|
||||||
if (fs.existsSync(downloadedFilePath)) {
|
if (fs.existsSync(downloadedFilePath)) {
|
||||||
|
|
Loading…
Reference in a new issue