🏁 Added progress bar support
This commit is contained in:
parent
299f140fcd
commit
7deec267de
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@ bin/ffmpeg
|
||||
music/*.mp3
|
||||
music/*.jpg
|
||||
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,17 +24,30 @@ 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 = {
|
||||
@ -148,15 +157,21 @@ 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') {
|
||||
|
||||
const content = require(rootdir + "database/" + file);
|
||||
|
||||
console.log(rootdir + "database/" + file);
|
||||
|
||||
content.forEach(element => {
|
||||
if (element.name.match(query)) {
|
||||
element.foundIn = file;
|
||||
element.type = (file === 'songs.json' ? 'song' : (file === 'albums.json' ? 'album' : 'artist'));
|
||||
result.push(element);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
res.json({result: result});
|
||||
|
Loading…
Reference in New Issue
Block a user