2019-09-17 16:49:23 +02:00
|
|
|
var express = require('express');
|
2019-09-17 17:07:08 +02:00
|
|
|
var YoutubeMp3Downloader = require("youtube-mp3-downloader");
|
|
|
|
|
2019-09-17 16:49:23 +02:00
|
|
|
var router = express.Router();
|
2019-09-17 17:07:08 +02:00
|
|
|
var YD = new YoutubeMp3Downloader({
|
|
|
|
"ffmpegPath": __dirname + "/../bin/ffmpeg",
|
|
|
|
"outputPath": __dirname + "/../music",
|
|
|
|
"youtubeVideoQuality": "highest",
|
|
|
|
"queueParallelism": 1,
|
|
|
|
"progressTimeout": 2000
|
|
|
|
});
|
2019-09-17 16:49:23 +02:00
|
|
|
|
|
|
|
/* GET home page. */
|
2019-09-17 17:07:08 +02:00
|
|
|
router.get('/', (req, res, next) => {
|
2019-09-17 16:49:23 +02:00
|
|
|
res.render('index', { title: 'Express' });
|
|
|
|
});
|
|
|
|
|
2019-09-17 17:07:08 +02:00
|
|
|
router.get('/download', (req, res, next) => {
|
|
|
|
YD.download(req.query.url);
|
|
|
|
|
|
|
|
YD.on('finished', (err, data) => {
|
|
|
|
if (err) {
|
|
|
|
res.json({ result: err });
|
|
|
|
} else {
|
|
|
|
res.json({ result: data });
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
|
2019-09-17 16:49:23 +02:00
|
|
|
module.exports = router;
|