Cassettea-api-node/routes/index.js

31 lines
702 B
JavaScript
Raw Normal View History

var express = require('express');
var YoutubeMp3Downloader = require("youtube-mp3-downloader");
var router = express.Router();
var YD = new YoutubeMp3Downloader({
"ffmpegPath": __dirname + "/../bin/ffmpeg",
"outputPath": __dirname + "/../music",
"youtubeVideoQuality": "highest",
"queueParallelism": 1,
"progressTimeout": 2000
});
/* GET home page. */
router.get('/', (req, res, next) => {
res.render('index', { title: 'Express' });
});
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 });
}
});
})
module.exports = router;