|
|
@ -100,12 +100,6 @@ class DownloadController {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Youtube-dl quality settings
|
|
|
|
|
|
|
|
if (data.quality == 'small')
|
|
|
|
|
|
|
|
option = 'worst'
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
option = 'best'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If alt download ( Quality settings and file format option doesn't work here )
|
|
|
|
// If alt download ( Quality settings and file format option doesn't work here )
|
|
|
|
if (data.alt) {
|
|
|
|
if (data.alt) {
|
|
|
|
let altFolder;
|
|
|
|
let altFolder;
|
|
|
@ -133,21 +127,25 @@ class DownloadController {
|
|
|
|
if (ws) {
|
|
|
|
if (ws) {
|
|
|
|
ws.socket.emit('end', altFolder.slice(17));
|
|
|
|
ws.socket.emit('end', altFolder.slice(17));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (data.url.match( /^.*(youtu.be\/|list=)([^#\&\?]*).*/)) {
|
|
|
|
if (data.url.match( /^.*(youtu.be\/|list=)([^#\&\?]*).*/)) {
|
|
|
|
playlistDownload(data)
|
|
|
|
playlistDownload(data);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
videoDownload(data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function videoDownload(data) {
|
|
|
|
// Download as mp4 if possible
|
|
|
|
// Download as mp4 if possible
|
|
|
|
let video = youtubedl(data.url, ['--format=mp4', '-f', option]);
|
|
|
|
let video = youtubedl(data.url, ['-f', data.quality]);
|
|
|
|
|
|
|
|
|
|
|
|
video.on('error', function(err) {
|
|
|
|
video.on('error', function(err) {
|
|
|
|
console.error(err);
|
|
|
|
console.error(err);
|
|
|
|
if (ws) {
|
|
|
|
if (ws) {
|
|
|
|
ws.socket.emit('error', err.toString());
|
|
|
|
ws.socket.emit('error', err.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
let ext;
|
|
|
|
let ext;
|
|
|
@ -158,13 +156,13 @@ class DownloadController {
|
|
|
|
ext = info.ext;
|
|
|
|
ext = info.ext;
|
|
|
|
let title = info.title.slice(0,50);
|
|
|
|
let title = info.title.slice(0,50);
|
|
|
|
DLFile = `${title.replace(/\s/g, '_')}.${ext}`;
|
|
|
|
DLFile = `${title.replace(/\s/g, '_')}.${ext}`;
|
|
|
|
DLFile = DLFile.replace(/[()]|[/]|[\\]|[?]|[!]/g, '_');
|
|
|
|
DLFile = DLFile.replace(/[()]|[/]|[\\]|[?]|[!]|[#]/g, '_');
|
|
|
|
|
|
|
|
|
|
|
|
// If no title use the ID
|
|
|
|
// If no title use the ID
|
|
|
|
if (title == '_') title = `_${info.id}`;
|
|
|
|
if (title == '_') title = `_${info.id}`;
|
|
|
|
// If user want to hide from the feed
|
|
|
|
// If user want to hide from the feed
|
|
|
|
if (data.feed == 'on')
|
|
|
|
if (data.feed == 'on')
|
|
|
|
DLFile = `hidden/${title}.${ext}`;
|
|
|
|
DLFile = `hidden/${DLFile}`;
|
|
|
|
|
|
|
|
|
|
|
|
video.pipe(fs.createWriteStream(`./public/uploads/${DLFile}`));
|
|
|
|
video.pipe(fs.createWriteStream(`./public/uploads/${DLFile}`));
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -182,17 +180,7 @@ class DownloadController {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
video.on('end', function() {
|
|
|
|
video.on('end', function() {
|
|
|
|
console.log('end');
|
|
|
|
if (data.format == 'mp3' || data.format == 'flac') {
|
|
|
|
if (ws) {
|
|
|
|
|
|
|
|
ws.socket.emit('message', 'end');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data.format == 'mp4' || data.format == 'webm') {
|
|
|
|
|
|
|
|
// If user requested mp4 directly attach the file
|
|
|
|
|
|
|
|
if (ws) {
|
|
|
|
|
|
|
|
ws.socket.emit('end', DLFile);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// If user requested an audio format, convert it
|
|
|
|
// If user requested an audio format, convert it
|
|
|
|
ffmpeg(`./public/uploads/${DLFile}`)
|
|
|
|
ffmpeg(`./public/uploads/${DLFile}`)
|
|
|
|
.noVideo()
|
|
|
|
.noVideo()
|
|
|
@ -202,17 +190,20 @@ class DownloadController {
|
|
|
|
.format(data.format)
|
|
|
|
.format(data.format)
|
|
|
|
.save(`./public/uploads/${DLFile.replace(`.${ext}`, `.${data.format}`)}`)
|
|
|
|
.save(`./public/uploads/${DLFile.replace(`.${ext}`, `.${data.format}`)}`)
|
|
|
|
.on('progress', (progress) => {
|
|
|
|
.on('progress', (progress) => {
|
|
|
|
wb.broadcast(progress.percent)
|
|
|
|
ws.socket.emit(progress.percent)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.on('end', () => {
|
|
|
|
.on('end', () => {
|
|
|
|
fs.unlinkSync(`./public/uploads/${DLFile}`);
|
|
|
|
fs.unlinkSync(`./public/uploads/${DLFile}`);
|
|
|
|
if (ws) {
|
|
|
|
if (ws) {
|
|
|
|
ws.socket.emit('end', DLFile.replace(`.${ext}`, `.${data.format}`));
|
|
|
|
ws.socket.emit('end', `./public/uploads/${DLFile.replace(`.${ext}`, `.${data.format}`)}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (ws) {
|
|
|
|
|
|
|
|
ws.socket.emit('end', `./public/uploads/${DLFile}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function playlistDownload(data) {
|
|
|
|
function playlistDownload(data) {
|
|
|
@ -223,7 +214,6 @@ class DownloadController {
|
|
|
|
if (ws) {
|
|
|
|
if (ws) {
|
|
|
|
ws.socket.emit('error', err.toString());
|
|
|
|
ws.socket.emit('error', err.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
let ext;
|
|
|
|
let ext;
|
|
|
@ -235,13 +225,14 @@ class DownloadController {
|
|
|
|
ext = info.ext;
|
|
|
|
ext = info.ext;
|
|
|
|
let title = info.title.slice(0,50);
|
|
|
|
let title = info.title.slice(0,50);
|
|
|
|
DLFile = `${title.replace(/\s/g, '_')}.${ext}`;
|
|
|
|
DLFile = `${title.replace(/\s/g, '_')}.${ext}`;
|
|
|
|
DLFile = DLFile.replace(/[()]|[/]|[\\]|[?]|[!]/g, '_');
|
|
|
|
DLFile = DLFile.replace(/[()]|[/]|[\\]|[?]|[!]|[#]/g, '_');
|
|
|
|
|
|
|
|
|
|
|
|
// If no title use the ID
|
|
|
|
// If no title use the ID
|
|
|
|
if (title == '_') title = `_${info.id}`;
|
|
|
|
if (title == '_') title = `_${info.id}`;
|
|
|
|
// If user want to hide from the feed
|
|
|
|
// If user want to hide from the feed
|
|
|
|
if (data.feed == 'on')
|
|
|
|
if (data.feed == 'on')
|
|
|
|
DLFile = `hidden/playlist/${title}.${ext}`;
|
|
|
|
DLFile = `hidden/playlist/${DLFile}`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
video.pipe(fs.createWriteStream(`./public/uploads/playlist/${DLFile}`));
|
|
|
|
video.pipe(fs.createWriteStream(`./public/uploads/playlist/${DLFile}`));
|
|
|
|
});
|
|
|
|
});
|
|
|
|