-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.js
30 lines (24 loc) · 895 Bytes
/
code.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
const express = require("express");
const ytdl = require("ytdl-core");
const app = express();
const { host, PORT } = require('./config.js');
app.use(express.json());
app.use(express.static("public"));
app.get("/",function(request,response){
response.sendFile(__dirname + "public/index.html");
});
app.get("/videoInfo",async function(request,response){
const videoURL = request.query.videoURL;
const info = await ytdl.getInfo(videoURL);
response.status(200).json(info);
});
app.get("/download",function(request,response){
const videoURL = request.query.videoURL;
const itag = request.query.itag;
const format = request.query.format;
response.header("Content-Disposition",'attachment;\ filename="video.'+format+'"');
ytdl(videoURL,{
filter: format => format.itag == itag
}).pipe(response);
});
app.listen(PORT, () => console.log(`Server is running on http://${host}:${PORT}`));