mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-04-22 04:33:20 +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 CONSTS = require('./consts')
|
||||||
const { spawn } = require('child_process')
|
const { spawn } = require('child_process')
|
||||||
const read_last_lines = require('read-last-lines');
|
const read_last_lines = require('read-last-lines');
|
||||||
|
var ps = require('ps-node');
|
||||||
|
|
||||||
const is_windows = process.platform === 'win32';
|
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() {
|
async function setPortItemFromENV() {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
config_api.setConfigItem('ytdl_port', backendPort.toString());
|
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/killAllDownloads', optionalJwt, async function(req, res) {
|
||||||
app.post('/api/fileStatusMp3', function(req, res) {
|
const result_obj = await killAllDownloads();
|
||||||
var name = decodeURIComponent(req.body.name + "");
|
res.send(result_obj);
|
||||||
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);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// gets all download mp3s
|
// gets all download mp3s
|
||||||
|
|||||||
@@ -50,6 +50,7 @@
|
|||||||
"passport-jwt": "^4.0.0",
|
"passport-jwt": "^4.0.0",
|
||||||
"passport-local": "^1.0.0",
|
"passport-local": "^1.0.0",
|
||||||
"progress": "^2.0.3",
|
"progress": "^2.0.3",
|
||||||
|
"ps-node": "^0.1.6",
|
||||||
"read-last-lines": "^1.7.2",
|
"read-last-lines": "^1.7.2",
|
||||||
"shortid": "^2.2.15",
|
"shortid": "^2.2.15",
|
||||||
"unzipper": "^0.10.10",
|
"unzipper": "^0.10.10",
|
||||||
|
|||||||
@@ -163,12 +163,8 @@ export class PostsService implements CanActivate {
|
|||||||
ui_uid: ui_uid}, this.httpOptions);
|
ui_uid: ui_uid}, this.httpOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
getFileStatusMp3(name: string) {
|
killAllDownloads() {
|
||||||
return this.http.post(this.path + 'fileStatusMp3', {name: name}, this.httpOptions);
|
return this.http.post(this.path + 'killAllDownloads', {}, this.httpOptions);
|
||||||
}
|
|
||||||
|
|
||||||
getFileStatusMp4(name: string) {
|
|
||||||
return this.http.post(this.path + 'fileStatusMp4', {name: name}, this.httpOptions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
loadNavItems() {
|
loadNavItems() {
|
||||||
|
|||||||
@@ -153,9 +153,13 @@
|
|||||||
<p><ng-container i18n="youtubedl archive setting Note">Note: This setting only applies to downloads on the Home page. If you would like to use youtube-dl archive functionality in subscriptions, head to the Main tab and activate this option there.</ng-container></p>
|
<p><ng-container i18n="youtubedl archive setting Note">Note: This setting only applies to downloads on the Home page. If you would like to use youtube-dl archive functionality in subscriptions, head to the Main tab and activate this option there.</ng-container></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-12 mt-3">
|
<div class="col-12 mt-2">
|
||||||
<mat-checkbox color="accent" [(ngModel)]="new_config['Downloader']['safe_download_override']"><ng-container i18n="Safe download override setting">Safe download override</ng-container></mat-checkbox>
|
<mat-checkbox color="accent" [(ngModel)]="new_config['Downloader']['safe_download_override']"><ng-container i18n="Safe download override setting">Safe download override</ng-container></mat-checkbox>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="col-12 mt-2">
|
||||||
|
<button (click)="killAllDownloads()" mat-stroked-button color="warn"><ng-container i18n="Kill all downloads button">Kill all downloads</ng-container></button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit, EventEmitter } from '@angular/core';
|
||||||
import { PostsService } from 'app/posts.services';
|
import { PostsService } from 'app/posts.services';
|
||||||
import { isoLangs } from './locales_list';
|
import { isoLangs } from './locales_list';
|
||||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||||
@@ -8,6 +8,7 @@ import { ArgModifierDialogComponent } from 'app/dialogs/arg-modifier-dialog/arg-
|
|||||||
import { CURRENT_VERSION } from 'app/consts';
|
import { CURRENT_VERSION } from 'app/consts';
|
||||||
import { MatCheckboxChange } from '@angular/material/checkbox';
|
import { MatCheckboxChange } from '@angular/material/checkbox';
|
||||||
import { CookiesUploaderDialogComponent } from 'app/dialogs/cookies-uploader-dialog/cookies-uploader-dialog.component';
|
import { CookiesUploaderDialogComponent } from 'app/dialogs/cookies-uploader-dialog/cookies-uploader-dialog.component';
|
||||||
|
import { ConfirmDialogComponent } from 'app/dialogs/confirm-dialog/confirm-dialog.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-settings',
|
selector: 'app-settings',
|
||||||
@@ -154,6 +155,34 @@ export class SettingsComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
killAllDownloads() {
|
||||||
|
const done = new EventEmitter<any>();
|
||||||
|
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
|
||||||
|
data: {
|
||||||
|
dialogTitle: 'Kill downloads',
|
||||||
|
dialogText: 'Are you sure you want to kill all downloads? Any subscription and non-subscription downloads will end immediately, though this operation may take a minute or so to complete.',
|
||||||
|
submitText: 'Kill all downloads',
|
||||||
|
doneEmitter: done
|
||||||
|
}
|
||||||
|
});
|
||||||
|
done.subscribe(confirmed => {
|
||||||
|
if (confirmed) {
|
||||||
|
this.postsService.killAllDownloads().subscribe(res => {
|
||||||
|
if (res['success']) {
|
||||||
|
dialogRef.close();
|
||||||
|
this.postsService.openSnackBar('Successfully killed all downloads!');
|
||||||
|
} else {
|
||||||
|
dialogRef.close();
|
||||||
|
this.postsService.openSnackBar('Failed to kill all downloads! Check logs for details.');
|
||||||
|
}
|
||||||
|
}, err => {
|
||||||
|
dialogRef.close();
|
||||||
|
this.postsService.openSnackBar('Failed to kill all downloads! Check logs for details.');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// snackbar helper
|
// snackbar helper
|
||||||
public openSnackBar(message: string, action: string = '') {
|
public openSnackBar(message: string, action: string = '') {
|
||||||
this.snackBar.open(message, action, {
|
this.snackBar.open(message, action, {
|
||||||
|
|||||||
Reference in New Issue
Block a user