🏁 Added progress bar support
This commit is contained in:
parent
299f140fcd
commit
7deec267de
3
.gitignore
vendored
3
.gitignore
vendored
@ -2,4 +2,5 @@ node_modules/
|
||||
bin/ffmpeg
|
||||
music/*.mp3
|
||||
music/*.jpg
|
||||
database/*.json
|
||||
database/*.json
|
||||
resultdata.json
|
@ -1,10 +1,11 @@
|
||||
var express = require('express');
|
||||
var YoutubeMp3Downloader = require("youtube-mp3-downloader");
|
||||
var fs = require('fs');
|
||||
var { getAudioDurationInSeconds } = require("get-audio-duration");
|
||||
var path = require('path');
|
||||
var urlParse = require("body-parser");
|
||||
var id3 = require('node-id3');
|
||||
var ytdl = require("ytdl-core");
|
||||
var ffmpeg = require("fluent-ffmpeg");
|
||||
|
||||
var router = express.Router();
|
||||
router.use(function(req, res, next) {
|
||||
@ -12,15 +13,10 @@ router.use(function(req, res, next) {
|
||||
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
||||
next();
|
||||
});
|
||||
|
||||
var YD = new YoutubeMp3Downloader({
|
||||
"ffmpegPath": path.join(__dirname + "/../bin/ffmpeg"),
|
||||
"outputPath": path.join(__dirname + "/../music"),
|
||||
"youtubeVideoQuality": "highest",
|
||||
"queueParallelism": 1,
|
||||
"progressTimeout": 2000
|
||||
});
|
||||
const rootdir = path.join(__dirname, '/../');
|
||||
ffmpeg.setFfmpegPath(rootdir + "bin/ffmpeg");
|
||||
|
||||
var downloadQueue = [];
|
||||
|
||||
/* GET home page. */
|
||||
router.get('/', (_req, res, _next) => {
|
||||
@ -28,18 +24,31 @@ router.get('/', (_req, res, _next) => {
|
||||
});
|
||||
|
||||
// Download route to download youtube video's
|
||||
router.get('/download', (req, res, _next) => {
|
||||
YD.download(req.query.url);
|
||||
router.get('/download/:url', (req, res, _next) => {
|
||||
ytdl.getInfo(req.params.url, (_err, info) => {
|
||||
const index = downloadQueue.push({'progress': 0, 'info': info}) - 1;
|
||||
let stream = ytdl(req.params.url, {
|
||||
quality: "highestaudio"
|
||||
//filter: 'audioonly',
|
||||
});
|
||||
|
||||
YD.on('finished', (err, data) => {
|
||||
if (err) {
|
||||
res.json({ result: err });
|
||||
} else {
|
||||
res.json({ result: data });
|
||||
}
|
||||
ffmpeg(stream)
|
||||
.audioBitrate(128)
|
||||
.on("progress", p => {
|
||||
if (downloadQueue[index]) downloadQueue[index].progress = p;
|
||||
})
|
||||
.save(`${rootdir}music/${info.title}.mp3`)
|
||||
.on("end", () => {
|
||||
downloadQueue.splice(index, 1);
|
||||
res.json({ result: info });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
router.get('/downloadqueue', (req, res, _next) => {
|
||||
res.json({ result: downloadQueue });
|
||||
})
|
||||
|
||||
function dbGet(type, id) {
|
||||
let db = {
|
||||
song: require(rootdir + 'database/songs.json'),
|
||||
@ -148,14 +157,20 @@ router.get('/search/:query', (req, res, _next) => {
|
||||
fs.readdir(rootdir + 'database/', (err, files) => {
|
||||
files.forEach(file => {
|
||||
|
||||
const content = require(rootdir + 'database/' + file);
|
||||
if (file !== '.gitkeep') {
|
||||
|
||||
content.forEach(element => {
|
||||
if (element.name.match(query)) {
|
||||
element.foundIn = file;
|
||||
result.push(element);
|
||||
}
|
||||
});
|
||||
const content = require(rootdir + "database/" + file);
|
||||
|
||||
console.log(rootdir + "database/" + file);
|
||||
|
||||
content.forEach(element => {
|
||||
if (element.name.match(query)) {
|
||||
element.type = (file === 'songs.json' ? 'song' : (file === 'albums.json' ? 'album' : 'artist'));
|
||||
result.push(element);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user