Merge branch 'p1rox-master'

This commit is contained in:
Timendum 2016-08-22 20:44:52 +02:00
commit fbafcafcd5
2 changed files with 16 additions and 20 deletions

View file

@ -1,4 +1,5 @@
<?php
include_once('FileHandler.php');
class Downloader
{
@ -14,16 +15,7 @@ class Downloader
public function __construct($post, $audio_only, $outfilename=False, $vformat=False)
{
$this->config = require dirname(__DIR__).'/config/config.php';
//this allows to use absolute paths
if(strpos($this->config["outputFolder"], "/") === 0)
{
$this->download_path = $this->config["outputFolder"];
}
else
{
$this->download_path = dirname(__DIR__).'/'.$this->config["outputFolder"];
}
$this->download_path = (new FileHandler())->get_downloads_folder();
if($this->config["log"])
{
@ -135,7 +127,7 @@ class Downloader
}
$config = require dirname(__DIR__).'/config/config.php';
$folder = dirname(__DIR__).'/'.$config["outputFolder"].'/';
$folder = $this->download_path;
foreach(glob($folder.'*.part') as $file)
{
@ -227,7 +219,7 @@ class Downloader
private function do_download()
{
$cmd = "youtube-dl";
$cmd .= " -o ".$this->config["outputFolder"]."/";
$cmd .= " -o ".$this->download_path."/";
$cmd .= escapeshellarg($this->outfilename);
if ($this->vformat)
@ -235,7 +227,6 @@ class Downloader
$cmd .= " --format ";
$cmd .= escapeshellarg($this->vformat);
}
if($this->audio_only)
{
$cmd .= " -x ";

View file

@ -16,7 +16,7 @@ class FileHandler
if(!$this->outuput_folder_exists())
return;
$folder = dirname(__DIR__).'/'.$this->config["outputFolder"].'/';
$folder = $this->get_downloads_folder().'/';
foreach(glob($folder.'*.*', GLOB_BRACE) as $file)
{
@ -57,7 +57,7 @@ class FileHandler
if(!$this->outuput_folder_exists())
return;
$folder = dirname(__DIR__).'/'.$this->config["logFolder"].'/';
$folder = $this->get_downloads_folder().'/';
foreach(glob($folder.'*.txt', GLOB_BRACE) as $file)
{
@ -92,7 +92,7 @@ class FileHandler
public function delete($id)
{
$folder = dirname(__DIR__).'/'.$this->config["outputFolder"].'/';
$folder = $this->get_downloads_folder().'/';
foreach(glob($folder.'*.*', GLOB_BRACE) as $file)
{
@ -118,10 +118,10 @@ class FileHandler
private function outuput_folder_exists()
{
if(!is_dir($this->config['outputFolder']))
if(!is_dir($this->get_downloads_folder()))
{
//Folder doesn't exist
if(!mkdir('./'.$this->config['outputFolder'], 0777))
if(!mkdir($this->get_downloads_folder(),0777))
{
return false; //No folder and creation failed
}
@ -139,12 +139,17 @@ class FileHandler
public function free_space()
{
return $this->to_human_filesize(disk_free_space($this->config["outputFolder"]));
return $this->to_human_filesize(disk_free_space($this->get_downloads_folder()));
}
public function get_downloads_folder()
{
return $this->config["outputFolder"];
$path = $this->config["outputFolder"];
if(strpos($path , "/") !== 0)
{
$path = dirname(__DIR__).'/' . $path;
}
return $path;
}
public function get_logs_folder()