Skip to content

Instantly share code, notes, and snippets.

@iagocavalcante
Created July 29, 2018 17:50
Show Gist options
  • Save iagocavalcante/c8e9f518a4bcdde469bf79119137bbb3 to your computer and use it in GitHub Desktop.
Save iagocavalcante/c8e9f518a4bcdde469bf79119137bbb3 to your computer and use it in GitHub Desktop.
export const listen = (__statics) => {
const app = express()
app.use(bodyParser.json({ limit: '250mb' }));
app.use(bodyParser.urlencoded({ limit: '250mb', extended: true }));
app.use(cors())
app.use(express.static(path.join(__statics, 'videos')))
app.post('/api/download', async (req, res) => {
try {
const info = await getInfoVideo(req.body.youtubeUrl.replace('https://www.youtube.com/watch?v=', ''))
const title = info.title.replace(/[!?@#$%^&*|\.\;]/g, "")
modules.manipulateFiles.createDir(path.join(__statics, `videos/${title}/`))
ytdl(req.body.youtubeUrl)
.pipe(fs.createWriteStream(path.join(__statics, `videos/${title}/${title}.mp4`)))
.on('finish', () => {
request.post('http://localhost:3000/api/thumbnail', { form: { info: info } })
res.status(200).json({ video: `ok` })
})
} catch (err) {
res.status(500).json(err)
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment