mirror of
https://github.com/timendum/Youtube-dl-WebUI.git
synced 2025-03-01 08:03:28 +08:00
Merge pull request #35 from pmoranga/fix_absolute_path
Fix absolute path, and use one provider for the path. Closes #33
This commit is contained in:
commit
fd868e4e72
2 changed files with 17 additions and 19 deletions
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
include_once('FileHandler.php');
|
||||
|
||||
class Downloader
|
||||
{
|
||||
|
@ -11,16 +12,8 @@ class Downloader
|
|||
public function __construct($post, $audio_only)
|
||||
{
|
||||
$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();
|
||||
|
||||
$this->audio_only = $audio_only;
|
||||
$this->urls = explode(",", $post);
|
||||
|
@ -118,7 +111,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)
|
||||
{
|
||||
|
@ -192,7 +185,7 @@ class Downloader
|
|||
private function do_download()
|
||||
{
|
||||
$cmd = "youtube-dl";
|
||||
$cmd .= " -o ".$this->config["outputFolder"]."/";
|
||||
$cmd .= " -o ".$this->download_path."/";
|
||||
$cmd .= escapeshellarg("%(title)s-%(uploader)s.%(ext)s");
|
||||
|
||||
if($this->audio_only)
|
||||
|
|
|
@ -18,7 +18,7 @@ class FileHandler
|
|||
if(!$this->outuput_folder_exists())
|
||||
return;
|
||||
|
||||
$folder = dirname(__DIR__).'/'.$this->config["outputFolder"].'/';
|
||||
$folder = $this->get_downloads_folder().'/';
|
||||
|
||||
foreach(glob($folder.'*'.$this->videos_ext, GLOB_BRACE) as $file)
|
||||
{
|
||||
|
@ -39,7 +39,7 @@ class FileHandler
|
|||
if(!$this->outuput_folder_exists())
|
||||
return;
|
||||
|
||||
$folder = dirname(__DIR__).'/'.$this->config["outputFolder"].'/';
|
||||
$folder = $this->get_downloads_folder().'/';
|
||||
|
||||
foreach(glob($folder.'*'.$this->musics_ext, GLOB_BRACE) as $file)
|
||||
{
|
||||
|
@ -55,7 +55,7 @@ class FileHandler
|
|||
|
||||
public function delete($id, $type)
|
||||
{
|
||||
$folder = dirname(__DIR__).'/'.$this->config["outputFolder"].'/';
|
||||
$folder = $this->get_downloads_folder().'/';
|
||||
$i = 0;
|
||||
|
||||
if($type === 'v')
|
||||
|
@ -83,10 +83,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
|
||||
}
|
||||
|
@ -104,12 +104,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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue