mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-04-13 05:41:28 +03:00
Removed erroneous code and added the ability to kill all downlaods
This commit is contained in:
@@ -30,6 +30,7 @@ var subscriptions_api = require('./subscriptions')
|
||||
const CONSTS = require('./consts')
|
||||
const { spawn } = require('child_process')
|
||||
const read_last_lines = require('read-last-lines');
|
||||
var ps = require('ps-node');
|
||||
|
||||
const is_windows = process.platform === 'win32';
|
||||
|
||||
@@ -503,6 +504,43 @@ async function getLatestVersion() {
|
||||
});
|
||||
}
|
||||
|
||||
async function killAllDownloads() {
|
||||
return new Promise(resolve => {
|
||||
ps.lookup({
|
||||
command: 'youtube-dl',
|
||||
}, function(err, resultList ) {
|
||||
if (err) {
|
||||
// failed to get list of processes
|
||||
logger.error('Failed to get a list of running youtube-dl processes.');
|
||||
logger.error(err);
|
||||
resolve({
|
||||
details: err,
|
||||
success: false
|
||||
});
|
||||
}
|
||||
|
||||
// processes that contain the string 'youtube-dl' in the name will be looped
|
||||
resultList.forEach(function( process ){
|
||||
if (process) {
|
||||
ps.kill(process.pid, 'SIGKILL', function( err ) {
|
||||
if (err) {
|
||||
// failed to kill, process may have ended on its own
|
||||
logger.warn(`Failed to kill process with PID ${process.pid}`);
|
||||
logger.warn(err);
|
||||
}
|
||||
else {
|
||||
logger.verbose(`Process ${process.pid} has been killed!`);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
resolve({
|
||||
success: true
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function setPortItemFromENV() {
|
||||
return new Promise(resolve => {
|
||||
config_api.setConfigItem('ytdl_port', backendPort.toString());
|
||||
@@ -1931,42 +1969,9 @@ app.post('/api/tomp4', optionalJwt, async function(req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
// gets the status of the mp3 file that's being downloaded
|
||||
app.post('/api/fileStatusMp3', function(req, res) {
|
||||
var name = decodeURIComponent(req.body.name + "");
|
||||
var exists = "";
|
||||
var fullpath = audioFolderPath + name + ".mp3";
|
||||
if (fs.existsSync(fullpath)) {
|
||||
exists = [basePath + audioFolderPath + name, getFileSizeMp3(name)];
|
||||
}
|
||||
else
|
||||
{
|
||||
var percent = 0;
|
||||
var size = getFileSizeMp3(name);
|
||||
var downloaded = getAmountDownloadedMp3(name);
|
||||
if (size > 0)
|
||||
percent = downloaded/size;
|
||||
exists = ["failed", getFileSizeMp3(name), percent];
|
||||
}
|
||||
res.send(exists);
|
||||
});
|
||||
|
||||
// gets the status of the mp4 file that's being downloaded
|
||||
app.post('/api/fileStatusMp4', function(req, res) {
|
||||
var name = decodeURIComponent(req.body.name);
|
||||
var exists = "";
|
||||
var fullpath = videoFolderPath + name + ".mp4";
|
||||
if (fs.existsSync(fullpath)) {
|
||||
exists = [basePath + videoFolderPath + name, getFileSizeMp4(name)];
|
||||
} else {
|
||||
var percent = 0;
|
||||
var size = getFileSizeMp4(name);
|
||||
var downloaded = getAmountDownloadedMp4(name);
|
||||
if (size > 0)
|
||||
percent = downloaded/size;
|
||||
exists = ["failed", getFileSizeMp4(name), percent];
|
||||
}
|
||||
res.send(exists);
|
||||
app.post('/api/killAllDownloads', optionalJwt, async function(req, res) {
|
||||
const result_obj = await killAllDownloads();
|
||||
res.send(result_obj);
|
||||
});
|
||||
|
||||
// gets all download mp3s
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
"passport-jwt": "^4.0.0",
|
||||
"passport-local": "^1.0.0",
|
||||
"progress": "^2.0.3",
|
||||
"ps-node": "^0.1.6",
|
||||
"read-last-lines": "^1.7.2",
|
||||
"shortid": "^2.2.15",
|
||||
"unzipper": "^0.10.10",
|
||||
|
||||
Reference in New Issue
Block a user