This repository has been archived by the owner on Jun 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
66 lines (49 loc) · 1.72 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
var express = require('express');
var fs = require('fs');
var ytdl = require('ytdl-core');
var app = express();
var { port } = require('./data/server_port.json');
app.use(express.json());
app.use(express.static("assets"));
app.get('/', (req,res) => {
res.sendFile(__dirname + '/assets/html/index.html');
});
app.get('/mp4', (req,res) => {
res.sendFile(__dirname + '/assets/html/mp4.html');
});
app.get('/api/', (req,res) => {
res.send('<center><h1>Hello world</h1></center>');
});
app.get('/api/callback', async (req,res) => {
var url = req.query.url;
var stream = await ytdl.getInfo(url);
var videoURL = stream.videoDetails.url;
var videoTitle = stream.videoDetails.title;
var someInformations = stream.videoDetails;
var writeStream = fs.writeFileSync('./data/user_recent_callback.txt', `Date: ${Date.now()} | Infos: ${someInformations}`);
var filename = videoTitle + '.mp3';
console.log(filename);
res.setHeader('Content-disposition', 'attachment;filename=' + filename);
ytdl(url, {
quality: 'highest',
format: 'mp3'
}).pipe(res);
});
app.get('/api/callback/output/video/mp4', async (req,res) => {
var url = req.query.url;
var stream = await ytdl.getInfo(url);
var videoURL = stream.videoDetails.url;
var videoTitle = stream.videoDetails.title;
var someInformations = stream.videoDetails;
var writeStream = fs.writeFileSync('./data/user_recent_callback.txt', `Date: ${Date.now()} | Infos: ${someInformations}`);
var filename = videoTitle + '.mp4';
console.log(filename);
res.setHeader('Content-disposition', 'attachment;filename=' + filename);
ytdl(url, {
quality: 'highest',
format: 'mp4'
}).pipe(res);
});
app.listen(port, () => {
console.log('Server connected');
});