This commit is contained in:
The Ghost of FOSS' Past 2024-10-28 10:58:13 -05:00
parent e88ed7ebb2
commit cefe207d65
3 changed files with 32 additions and 5 deletions

View file

@ -4,10 +4,13 @@ const ytSearch = require('yt-search');
const { exec } = require('child_process');
const fs = require('fs');
const path = require('path');
const cors = require('cors');
const app = express();
const port = 4286;
//use cors
app.use(cors());
// Middleware to parse JSON
app.use(express.json());
@ -50,10 +53,10 @@ app.get('/download', (req, res) => {
}
// Set the output file path
const outputPath = path.join(__dirname, 'downloads', '%(title)s.%(ext)s');
const outputPath = path.join(__dirname, '/tmp/downloads', '%(title)s.%(ext)s');
// Create downloads directory if it doesn't exist
fs.mkdirSync(path.join(__dirname, 'downloads'), { recursive: true });
// Create /tmp/downloads directory if it doesn't exist
fs.mkdirSync(path.join(__dirname, '/tmp/downloads'), { recursive: true });
// Use yt-dlp to download the video
exec(`yt-dlp -o "${outputPath}" "${videoUrl}"`, (error, stdout, stderr) => {
@ -69,7 +72,7 @@ app.get('/download', (req, res) => {
}
// Full path of the downloaded file
const downloadedFilePath = path.join(__dirname, 'downloads', filename);
const downloadedFilePath = path.join(__dirname, '/tmp/downloads', filename);
// Check if the file exists and send it
if (fs.existsSync(downloadedFilePath)) {

23
package-lock.json generated
View file

@ -9,6 +9,7 @@
"version": "1.0.0",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.21.1",
"fs": "^0.0.1-security",
"path": "^0.12.7",
@ -309,6 +310,19 @@
"integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==",
"license": "MIT"
},
"node_modules/cors": {
"version": "2.8.5",
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
"integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
"license": "MIT",
"dependencies": {
"object-assign": "^4",
"vary": "^1"
},
"engines": {
"node": ">= 0.10"
}
},
"node_modules/css-select": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/css-select/-/css-select-5.1.0.tgz",
@ -1059,6 +1073,15 @@
"url": "https://github.com/fb55/nth-check?sponsor=1"
}
},
"node_modules/object-assign": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
"integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==",
"license": "MIT",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/object-inspect": {
"version": "1.13.2",
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.2.tgz",

View file

@ -10,6 +10,7 @@
"license": "SEE LICENSE IN LICENSE",
"description": "",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.21.1",
"fs": "^0.0.1-security",
"path": "^0.12.7",