-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (25 loc) · 952 Bytes
/
index.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
const express = require('express')
const fs = require('fs')
const app = express()
const path = require('path')
const cors = require('cors')
const ytdl = require('ytdl-core')
app.use(express.static(path.join(__dirname, 'client', 'build')))
app.use(cors())
app.get('/api/video_download', (req, res) => {
const { URL, type, title, quality } = req.query
console.log(URL, type, title, quality )
if ( type === 'video'&& quality ) {
ytdl(URL, { quality }).pipe(res)
res.header('Content-Disposition', `attachment; filename="OutTube-Video.mp4"`)
} else if (type === 'audio') {
ytdl(URL, {filter: quality}).pipe(res)
res.header('Content-Disposition', `attachment; filename="OutTube-Audio.mp3"`)
}
console.log('Sent to Client')
})
app.use((req, res, next) => {
res.sendFile(path.join(__dirname, 'client', 'build', 'index.html'))
})
const port = process.env.PORT || 5050
app.listen(port, () => console.log(`App is listening on port ${port}`))