🏁 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/*.mp3
|
||||||
music/*.jpg
|
music/*.jpg
|
||||||
database/*.json
|
database/*.json
|
||||||
|
resultdata.json
|
@ -1,10 +1,11 @@
|
|||||||
var express = require('express');
|
var express = require('express');
|
||||||
var YoutubeMp3Downloader = require("youtube-mp3-downloader");
|
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var { getAudioDurationInSeconds } = require("get-audio-duration");
|
var { getAudioDurationInSeconds } = require("get-audio-duration");
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var urlParse = require("body-parser");
|
var urlParse = require("body-parser");
|
||||||
var id3 = require('node-id3');
|
var id3 = require('node-id3');
|
||||||
|
var ytdl = require("ytdl-core");
|
||||||
|
var ffmpeg = require("fluent-ffmpeg");
|
||||||
|
|
||||||
var router = express.Router();
|
var router = express.Router();
|
||||||
router.use(function(req, res, next) {
|
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");
|
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
||||||
next();
|
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, '/../');
|
const rootdir = path.join(__dirname, '/../');
|
||||||
|
ffmpeg.setFfmpegPath(rootdir + "bin/ffmpeg");
|
||||||
|
|
||||||
|
var downloadQueue = [];
|
||||||
|
|
||||||
/* GET home page. */
|
/* GET home page. */
|
||||||
router.get('/', (_req, res, _next) => {
|
router.get('/', (_req, res, _next) => {
|
||||||
@ -28,17 +24,30 @@ router.get('/', (_req, res, _next) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Download route to download youtube video's
|
// Download route to download youtube video's
|
||||||
router.get('/download', (req, res, _next) => {
|
router.get('/download/:url', (req, res, _next) => {
|
||||||
YD.download(req.query.url);
|
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) => {
|
ffmpeg(stream)
|
||||||
if (err) {
|
.audioBitrate(128)
|
||||||
res.json({ result: err });
|
.on("progress", p => {
|
||||||
} else {
|
if (downloadQueue[index]) downloadQueue[index].progress = p;
|
||||||
res.json({ result: data });
|
})
|
||||||
}
|
.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) {
|
function dbGet(type, id) {
|
||||||
let db = {
|
let db = {
|
||||||
@ -148,15 +157,21 @@ router.get('/search/:query', (req, res, _next) => {
|
|||||||
fs.readdir(rootdir + 'database/', (err, files) => {
|
fs.readdir(rootdir + 'database/', (err, files) => {
|
||||||
files.forEach(file => {
|
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 => {
|
content.forEach(element => {
|
||||||
if (element.name.match(query)) {
|
if (element.name.match(query)) {
|
||||||
element.foundIn = file;
|
element.type = (file === 'songs.json' ? 'song' : (file === 'albums.json' ? 'album' : 'artist'));
|
||||||
result.push(element);
|
result.push(element);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
res.json({result: result});
|
res.json({result: result});
|
||||||
|
Loading…
Reference in New Issue
Block a user