-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
45 lines (35 loc) · 1.09 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const express = require("express")
const ytdl = require("ytdl-core")
const path = require("path")
const fs = require("fs");
const deletefile = require("./utiles/deletefile")
const app = express()
const port = process.env.PORT || 3000;
var views = path.join(__dirname, "views");
app.set('view engine','ejs');
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.get('/',((req,resp)=>{
const xys = false;
resp.render('home',{value : xys})
}))
app.post('/',(async(req,resp)=>{
try{
url = req.body.url
const getInformation = await ytdl.getInfo(url,(info)=>{
return info;
})
const title = getInformation.videoDetails.title
ytdl(url)
.pipe(fs.createWriteStream(`views/${title}.mp4`)).on('close', async() => {
resp.download(path.join(views,`${title}.mp4`))
await deletefile(title)
});
}
catch{
resp.send("Invalid")
}
}))
app.listen(port, () => {
console.log(`Hosted on ${port} port`);
});