2015-10-31 14:42:25 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Config class
|
2016-08-01 11:29:13 +00:00
|
|
|
*/
|
2015-10-31 14:42:25 +00:00
|
|
|
namespace Alltube;
|
2016-03-29 23:49:08 +00:00
|
|
|
|
2015-10-31 14:42:25 +00:00
|
|
|
use Symfony\Component\Yaml\Yaml;
|
2016-03-29 23:49:08 +00:00
|
|
|
|
2015-10-31 14:42:25 +00:00
|
|
|
/**
|
2016-08-01 11:29:13 +00:00
|
|
|
* Manage config parameters
|
|
|
|
*/
|
2016-03-29 23:49:08 +00:00
|
|
|
class Config
|
2015-10-31 14:42:25 +00:00
|
|
|
{
|
2016-08-01 11:29:13 +00:00
|
|
|
/**
|
|
|
|
* Singleton instance
|
|
|
|
* @var Config
|
|
|
|
*/
|
2016-03-29 23:49:08 +00:00
|
|
|
private static $instance;
|
2015-10-31 14:42:25 +00:00
|
|
|
|
2016-08-01 11:29:13 +00:00
|
|
|
/**
|
|
|
|
* youtube-dl binary path
|
|
|
|
* @var string
|
|
|
|
*/
|
2015-10-31 14:56:00 +00:00
|
|
|
public $youtubedl = 'vendor/rg3/youtube-dl/youtube_dl/__main__.py';
|
2016-08-01 11:29:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* python binary path
|
|
|
|
* @var string
|
|
|
|
*/
|
2015-10-31 14:42:25 +00:00
|
|
|
public $python = '/usr/bin/python';
|
2016-08-01 11:29:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* youtube-dl parameters
|
|
|
|
* @var array
|
|
|
|
*/
|
2016-04-12 09:49:50 +00:00
|
|
|
public $params = array('--no-playlist', '--no-warnings', '-f best[protocol^=http]', '--playlist-end', 1);
|
2016-08-01 11:29:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable audio conversion
|
|
|
|
* @var bool
|
|
|
|
*/
|
2015-10-31 14:42:25 +00:00
|
|
|
public $convert = false;
|
2016-08-01 11:29:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* avconv or ffmpeg binary path
|
|
|
|
* @var string
|
|
|
|
*/
|
2015-11-21 19:54:38 +00:00
|
|
|
public $avconv = 'vendor/bin/ffmpeg';
|
2016-08-01 11:29:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* rtmpdump binary path
|
|
|
|
* @var string
|
|
|
|
*/
|
2016-04-12 19:13:43 +00:00
|
|
|
public $rtmpdump = 'vendor/bin/rtmpdump';
|
2016-08-01 11:29:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* curl binary path
|
|
|
|
* @var string
|
|
|
|
*/
|
2016-07-30 12:01:00 +00:00
|
|
|
public $curl = '/usr/bin/curl';
|
2016-08-01 11:29:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* curl parameters
|
|
|
|
* @var array
|
|
|
|
*/
|
2016-04-12 09:49:50 +00:00
|
|
|
public $curl_params = array();
|
2015-10-31 14:42:25 +00:00
|
|
|
|
2016-08-18 23:07:51 +00:00
|
|
|
private $configFile;
|
|
|
|
|
2015-10-31 14:50:32 +00:00
|
|
|
/**
|
|
|
|
* Config constructor
|
|
|
|
*/
|
2016-08-18 23:07:51 +00:00
|
|
|
private function __construct($yamlfile)
|
2015-10-31 14:50:32 +00:00
|
|
|
{
|
2016-08-18 23:07:51 +00:00
|
|
|
$this->file = $yamlfile;
|
2015-12-18 23:58:14 +00:00
|
|
|
if (is_file($yamlfile)) {
|
|
|
|
$yaml = Yaml::parse(file_get_contents($yamlfile));
|
|
|
|
if (isset($yaml) && is_array($yaml)) {
|
2016-03-29 23:49:08 +00:00
|
|
|
foreach ($yaml as $param => $value) {
|
2016-07-27 11:11:38 +00:00
|
|
|
if (isset($this->$param) && isset($value)) {
|
2015-12-18 23:58:14 +00:00
|
|
|
$this->$param = $value;
|
|
|
|
}
|
2015-10-31 14:57:36 +00:00
|
|
|
}
|
2015-10-31 14:42:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (getenv('CONVERT')) {
|
|
|
|
$this->convert = getenv('CONVERT');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-31 14:50:32 +00:00
|
|
|
/**
|
|
|
|
* Get singleton instance
|
2016-02-28 22:04:53 +00:00
|
|
|
*
|
2015-10-31 14:50:32 +00:00
|
|
|
* @return Config
|
|
|
|
*/
|
2016-08-18 23:07:51 +00:00
|
|
|
public static function getInstance($yamlfile = __DIR__.'/../config.yml')
|
2015-10-31 14:50:32 +00:00
|
|
|
{
|
2016-08-18 23:07:51 +00:00
|
|
|
if (is_null(self::$instance) || self::$instance->file != $yamlfile) {
|
|
|
|
self::$instance = new Config($yamlfile);
|
2015-10-31 14:42:25 +00:00
|
|
|
}
|
2016-03-29 23:49:08 +00:00
|
|
|
return self::$instance;
|
2015-10-31 14:42:25 +00:00
|
|
|
}
|
2016-07-30 10:40:49 +00:00
|
|
|
|
2016-08-01 11:29:13 +00:00
|
|
|
/**
|
|
|
|
* Destroy singleton instance
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-07-30 10:40:49 +00:00
|
|
|
public static function destroyInstance()
|
|
|
|
{
|
|
|
|
self::$instance = null;
|
|
|
|
}
|
2015-10-31 14:42:25 +00:00
|
|
|
}
|