From 1547f18fe0f757c0c82b745077527d4c50749a53 Mon Sep 17 00:00:00 2001 From: p1rox Date: Fri, 13 Mar 2015 21:30:48 +0100 Subject: [PATCH 1/2] Add background jobs view and possibility to kill them all --- class/Downloader.php | 48 ++++++++++++++++++++++++++++++++++++++++++++ index.php | 25 ++++++++++------------- list.php | 7 ++++--- login.php | 5 +++-- views/footer.php | 5 +++++ views/header.php | 42 +++++++++++++++++++++++++++++++++++--- 6 files changed, 110 insertions(+), 22 deletions(-) diff --git a/class/Downloader.php b/class/Downloader.php index b7a94d8..fbb5b34 100644 --- a/class/Downloader.php +++ b/class/Downloader.php @@ -54,6 +54,54 @@ class Downloader return $config["max_dl"]; } + public static function get_current_background_jobs() + { + exec("ps -A -o user,pid,etime,cmd | grep -v grep | grep youtube-dl", $output); + + $bjs = []; + + if(count($output) > 0) + { + foreach($output as $line) + { + $line = explode(' ', preg_replace ("/ +/", " ", $line), 4); + $bjs[] = array( + 'user' => $line[0], + 'pid' => $line[1], + 'time' => $line[2], + 'cmd' => $line[3] + ); + } + + return $bjs; + } + else + { + return null; + } + } + + public static function kill_them_all() + { + exec("ps -A -o pid,cmd | grep -v grep | grep youtube-dl | awk '{print $1}'", $output); + + if(count($output) <= 0) + return; + + foreach($output as $p) + { + shell_exec("kill ".$p); + } + + $config = require dirname(__DIR__).'/config/config.php'; + $folder = dirname(__DIR__).'/'.$config["outputFolder"].'/'; + + foreach(glob($folder.'*.part') as $file) + { + unlink($file); + } + } + private function check_requirements($audio_only) { if($this->is_youtubedl_installed() != 0) diff --git a/index.php b/index.php index 50319be..71ec5c7 100644 --- a/index.php +++ b/index.php @@ -1,17 +1,24 @@ is_logged_in()) { header("Location: login.php"); } else { + if(isset($_GET['kill']) && !empty($_GET['kill']) && $_GET['kill'] === "all") + { + Downloader::kill_them_all(); + } + if(isset($_POST['urls']) && !empty($_POST['urls'])) { $audio_only = false; @@ -25,19 +32,10 @@ if(!isset($_SESSION['errors'])) { - if($audio_only) - { - header("Location: list.php?type=m"); - } - else - { - header("Location: list.php?type=v"); - } + header("Location: index.php"); } } } - - require 'views/header.php'; ?>

@@ -75,7 +73,6 @@

Info

-

Background downloads :

Free space : free_space(); ?>

Download folder : get_downloads_folder(); ?>

diff --git a/list.php b/list.php index 0368676..b7eb4bd 100644 --- a/list.php +++ b/list.php @@ -1,7 +1,8 @@ + \ No newline at end of file diff --git a/views/header.php b/views/header.php index ac04911..e28c58c 100644 --- a/views/header.php +++ b/views/header.php @@ -4,6 +4,7 @@ Youtube-dl WebUI +