Add JSON info page

This commit is contained in:
Timendum 2017-10-06 22:39:48 +02:00
parent 01643be4af
commit 2bcba463b4
3 changed files with 118 additions and 1 deletions

View file

@ -90,6 +90,18 @@ class Downloader
}
public function info()
{
$info = $this->do_info();
if(isset($this->errors) && count($this->errors) > 0)
{
$_SESSION['errors'] = $this->errors;
}
return $info;
}
public static function background_jobs()
{
return shell_exec("ps aux | grep -v grep | grep -v \"youtube-dl -U\" | grep youtube-dl | wc -l");
@ -149,7 +161,7 @@ class Downloader
}
}
private function check_requirements($audio_only)
private function check_requirements($audio_only=False)
{
if($this->is_youtubedl_installed() != 0)
{
@ -187,6 +199,12 @@ class Downloader
return $r;
}
private function is_python_installed()
{
exec("which python", $out, $r);
return $r;
}
private function is_valid_url($url)
{
return filter_var($url, FILTER_VALIDATE_URL);
@ -268,6 +286,24 @@ class Downloader
shell_exec($cmd);
}
private function do_info()
{
$cmd = "youtube-dl -J ";
foreach($this->urls as $url)
{
$cmd .= " ".escapeshellarg($url);
}
if ($this->is_python_installed() == 0)
{
$cmd .= " | python -m json.tool";
}
return shell_exec($cmd);
}
}
?>

80
info.php Normal file
View file

@ -0,0 +1,80 @@
<?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();
}
$json = False;
if(isset($_POST['urls']) && !empty($_POST['urls']))
{
$downloader = new Downloader($_POST['urls']);
$json = $downloader->info();
}
}
?>
<div class="container">
<h1>JSON Info</h1>
<?php
if(isset($_SESSION['errors']) && $_SESSION['errors'] > 0)
{
foreach ($_SESSION['errors'] as $e)
{
echo "<div class=\"alert alert-warning\" role=\"alert\">$e</div>";
}
}
?>
<form id="info-form" action="info.php" method="post">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon" id="urls-addon">URLs:</span>
<input class="form-control" id="url" name="urls" placeholder="Link(s) separated by a comma" type="text" aria-describedby="urls-addon" required/>
</div>
</div>
<div class="row">
<div class="col-md-2">
<button type="submit" class="btn btn-primary">Query</button>
</div>
<div class="col-md-10">
</div>
</div>
</form>
<br>
<div class="row">
<?php
if ($json)
{
?>
<div class="panel panel-info">
<div class="panel-heading"><h3 class="panel-title">Info</h3></div>
<div class="panel-body">
<textarea rows="50" class="form-control"><?php echo $json ?></textarea>
</div>
</div>
<?php
}
?>
</div>
</div>
<?php
unset($_SESSION['errors']);
require 'views/footer.php';
?>

View file

@ -24,6 +24,7 @@
if($session->is_logged_in() && isset($file))
{
echo ' <li><a href="./">Download</a></li>';
echo ' <li><a href="./info.php">JSON Info</a></li>';
// List of files
$filesCount = count($file->listFiles());
if ($filesCount < 1) {