mirror of
https://github.com/timendum/Youtube-dl-WebUI.git
synced 2025-03-01 08:03:28 +08:00
Merge pull request #2 from p1rox/background_jobs_manager
Background jobs manager
This commit is contained in:
commit
a54409d624
6 changed files with 111 additions and 23 deletions
|
@ -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)
|
||||
|
|
27
index.php
27
index.php
|
@ -1,17 +1,24 @@
|
|||
<?php
|
||||
require 'class/Session.php';
|
||||
require 'class/FileHandler.php';
|
||||
require 'class/Downloader.php';
|
||||
require_once 'class/Session.php';
|
||||
require_once 'class/Downloader.php';
|
||||
require_once 'class/FileHandler.php';
|
||||
|
||||
$session = Session::getInstance();
|
||||
$file = new FileHandler;
|
||||
|
||||
require 'views/header.php';
|
||||
|
||||
if(!$session->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';
|
||||
?>
|
||||
<div class="container">
|
||||
<br>
|
||||
|
@ -75,7 +73,6 @@
|
|||
<div class="panel panel-info">
|
||||
<div class="panel-heading"><h3 class="panel-title">Info</h3></div>
|
||||
<div class="panel-body">
|
||||
<p><b>Background downloads : <?php echo Downloader::background_jobs()." / ".Downloader::max_background_jobs() ?> </b></p>
|
||||
<p>Free space : <?php echo $file->free_space(); ?></b></p>
|
||||
<p>Download folder : <?php echo $file->get_downloads_folder(); ?></p>
|
||||
</div>
|
||||
|
@ -90,7 +87,7 @@
|
|||
<p><b>With which sites does it works ?</b></p>
|
||||
<p><a href="http://rg3.github.io/youtube-dl/supportedsites.html">Here</a> is the list of the supported sites</p>
|
||||
<p><b>How can I download the video on my computer ?</b></p>
|
||||
<p>Go to <a href="./list.php">List of videos</a>, choose one, right click on the link and do "Save target as ..." </p>
|
||||
<p>Go to <a href="./list.php?type=v">List of videos</a>, choose one, right click on the link and do "Save target as ..." </p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
7
list.php
7
list.php
|
@ -1,7 +1,8 @@
|
|||
<?php
|
||||
require 'class/Session.php';
|
||||
require 'class/FileHandler.php';
|
||||
|
||||
require_once 'class/Session.php';
|
||||
require_once 'class/Downloader.php';
|
||||
require_once 'class/FileHandler.php';
|
||||
|
||||
$session = Session::getInstance();
|
||||
$file = new FileHandler;
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
<?php
|
||||
require 'class/Session.php';
|
||||
$session = Session::getInstance();
|
||||
require_once 'class/Session.php';
|
||||
require_once 'class/Downloader.php';
|
||||
|
||||
$session = Session::getInstance();
|
||||
$loginError = "";
|
||||
|
||||
if(isset($_POST["password"]))
|
||||
|
|
|
@ -6,5 +6,10 @@
|
|||
<script type="text/javascript" src="js/jquery-1.11.1.min.js"></script>
|
||||
<script type="text/javascript" src="js/bootstrap.min.js"></script>
|
||||
<script type="text/javascript" src="js/app.js"></script>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
$("#url").focus();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -4,6 +4,7 @@
|
|||
<meta charset="utf-8">
|
||||
<title>Youtube-dl WebUI</title>
|
||||
<link rel="stylesheet" href="css/bootstrap.min.css" media="screen">
|
||||
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="navbar navbar-default navbar-fixed-top">
|
||||
|
@ -20,14 +21,49 @@
|
|||
<li><a href="./">Download</a></li>
|
||||
<li><a href="./list.php?type=v">List of videos</a></li>
|
||||
<li><a href="./list.php?type=m">List of musics</a></li>
|
||||
<?php
|
||||
if($session->is_logged_in())
|
||||
{
|
||||
?>
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
|
||||
<?php if(Downloader::background_jobs() > 0) echo "<b>"; ?>Background downloads : <?php echo Downloader::background_jobs()." / ".Downloader::max_background_jobs(); if(Downloader::background_jobs() > 0) echo "</b>"; ?> <span class="caret"></span></a>
|
||||
<ul class="dropdown-menu" role="menu">
|
||||
<?php
|
||||
if(Downloader::get_current_background_jobs() != null)
|
||||
{
|
||||
foreach(Downloader::get_current_background_jobs() as $key)
|
||||
{
|
||||
if (strpos($key['cmd'], '-x') !== false) //Music
|
||||
{
|
||||
echo "<li><a href=\"#\"><i class=\"fa fa-music\"></i> Elapsed download time : ".$key['time']."</a></li>";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "<li><a href=\"#\"><i class=\"fa fa-video-camera\"></i> Elapsed download time : ".$key['time']."</a></li>";
|
||||
}
|
||||
}
|
||||
|
||||
echo "<li class=\"divider\"></li>";
|
||||
echo "<li><a href=\"./index.php?kill=all\">Kill all downloads</a></li>";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "<li><a>No jobs !</a></li>";
|
||||
}
|
||||
|
||||
?>
|
||||
</ul>
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
<?php
|
||||
if($session->is_logged_in())
|
||||
{
|
||||
?>
|
||||
<li><a href="./logout.php">Logout</a></li>
|
||||
<?php
|
||||
echo "<li><a href=\"./logout.php\">Logout</a></li>";
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
|
|
Loading…
Reference in a new issue