2015-10-31 14:42:25 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* Config class.
|
2016-08-01 11:29:13 +00:00
|
|
|
*/
|
2016-12-05 12:12:27 +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-09-07 22:28:28 +00:00
|
|
|
* Manage config parameters.
|
2016-08-01 11:29:13 +00:00
|
|
|
*/
|
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
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* Singleton instance.
|
|
|
|
*
|
2016-08-01 11:29:13 +00:00
|
|
|
* @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
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* youtube-dl binary path.
|
|
|
|
*
|
2016-08-01 11:29:13 +00:00
|
|
|
* @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
|
|
|
|
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* python binary path.
|
|
|
|
*
|
2016-08-01 11:29:13 +00:00
|
|
|
* @var string
|
|
|
|
*/
|
2015-10-31 14:42:25 +00:00
|
|
|
public $python = '/usr/bin/python';
|
2016-08-01 11:29:13 +00:00
|
|
|
|
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* youtube-dl parameters.
|
|
|
|
*
|
2016-08-01 11:29:13 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2016-09-07 22:28:28 +00:00
|
|
|
public $params = ['--no-playlist', '--no-warnings', '-f best[protocol^=http]', '--playlist-end', 1];
|
2016-08-01 11:29:13 +00:00
|
|
|
|
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* Enable audio conversion.
|
|
|
|
*
|
2016-08-01 11:29:13 +00:00
|
|
|
* @var bool
|
|
|
|
*/
|
2015-10-31 14:42:25 +00:00
|
|
|
public $convert = false;
|
2016-08-01 11:29:13 +00:00
|
|
|
|
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* avconv or ffmpeg binary path.
|
|
|
|
*
|
2016-08-01 11:29:13 +00:00
|
|
|
* @var string
|
|
|
|
*/
|
2015-11-21 19:54:38 +00:00
|
|
|
public $avconv = 'vendor/bin/ffmpeg';
|
2016-08-01 11:29:13 +00:00
|
|
|
|
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* rtmpdump binary path.
|
|
|
|
*
|
2016-08-01 11:29:13 +00:00
|
|
|
* @var string
|
|
|
|
*/
|
2016-04-12 19:13:43 +00:00
|
|
|
public $rtmpdump = 'vendor/bin/rtmpdump';
|
2016-08-01 11:29:13 +00:00
|
|
|
|
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* curl binary path.
|
|
|
|
*
|
2016-08-01 11:29:13 +00:00
|
|
|
* @var string
|
|
|
|
*/
|
2016-07-30 12:01:00 +00:00
|
|
|
public $curl = '/usr/bin/curl';
|
2016-08-01 11:29:13 +00:00
|
|
|
|
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* curl parameters.
|
|
|
|
*
|
2016-08-01 11:29:13 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2016-09-07 22:28:28 +00:00
|
|
|
public $curl_params = [];
|
2015-10-31 14:42:25 +00:00
|
|
|
|
2017-01-10 22:37:29 +00:00
|
|
|
/**
|
|
|
|
* Disable URL rewriting.
|
2017-01-10 22:39:58 +00:00
|
|
|
*
|
|
|
|
* @var bool
|
2017-01-10 22:37:29 +00:00
|
|
|
*/
|
|
|
|
public $uglyUrls = false;
|
|
|
|
|
2016-09-05 22:36:47 +00:00
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* YAML config file path.
|
|
|
|
*
|
2016-09-05 22:36:47 +00:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $file;
|
2016-08-18 23:07:51 +00:00
|
|
|
|
2015-10-31 14:50:32 +00:00
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* Config constructor.
|
2016-09-05 22:36:47 +00:00
|
|
|
*
|
2016-10-18 07:54:08 +00:00
|
|
|
* Available options:
|
|
|
|
* * youtubedl: youtube-dl binary path
|
|
|
|
* * python: Python binary path
|
|
|
|
* * avconv: avconv or ffmpeg binary path
|
|
|
|
* * rtmpdump: rtmpdump binary path
|
|
|
|
* * curl: curl binary path
|
|
|
|
* * params: Array of youtube-dl parameters
|
|
|
|
* * curl_params: Array of curl parameters
|
|
|
|
* * convert: Enable conversion?
|
|
|
|
*
|
|
|
|
* @param array $options Options
|
2015-10-31 14:50:32 +00:00
|
|
|
*/
|
2016-10-18 07:54:08 +00:00
|
|
|
public function __construct(array $options)
|
2015-10-31 14:50:32 +00:00
|
|
|
{
|
2016-10-18 07:54:08 +00:00
|
|
|
if (isset($options) && is_array($options)) {
|
|
|
|
foreach ($options as $option => $value) {
|
|
|
|
if (isset($this->$option) && isset($value)) {
|
|
|
|
$this->$option = $value;
|
2015-10-31 14:57:36 +00:00
|
|
|
}
|
2015-10-31 14:42:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (getenv('CONVERT')) {
|
2016-10-10 19:30:07 +00:00
|
|
|
$this->convert = (bool) getenv('CONVERT');
|
2015-10-31 14:42:25 +00:00
|
|
|
}
|
2016-12-22 12:46:31 +00:00
|
|
|
if (getenv('PYTHON')) {
|
|
|
|
$this->python = getenv('PYTHON');
|
|
|
|
}
|
2015-10-31 14:42:25 +00:00
|
|
|
}
|
|
|
|
|
2015-10-31 14:50:32 +00:00
|
|
|
/**
|
2016-10-18 07:54:08 +00:00
|
|
|
* Get Config singleton instance from YAML config file.
|
2016-02-28 22:04:53 +00:00
|
|
|
*
|
2016-09-05 22:36:47 +00:00
|
|
|
* @param string $yamlfile YAML config file name
|
|
|
|
*
|
2015-10-31 14:50:32 +00:00
|
|
|
* @return Config
|
|
|
|
*/
|
2016-08-18 23:13:51 +00:00
|
|
|
public static function getInstance($yamlfile = 'config.yml')
|
2015-10-31 14:50:32 +00:00
|
|
|
{
|
2016-10-18 07:54:08 +00:00
|
|
|
$yamlPath = __DIR__.'/../'.$yamlfile;
|
2016-08-18 23:07:51 +00:00
|
|
|
if (is_null(self::$instance) || self::$instance->file != $yamlfile) {
|
2016-10-18 07:54:08 +00:00
|
|
|
if (is_file($yamlfile)) {
|
|
|
|
$options = Yaml::parse(file_get_contents($yamlPath));
|
|
|
|
} elseif ($yamlfile == 'config.yml') {
|
|
|
|
/*
|
|
|
|
Allow for the default file to be missing in order to
|
|
|
|
not surprise users that did not create a config file
|
|
|
|
*/
|
|
|
|
$options = [];
|
|
|
|
} else {
|
|
|
|
throw new \Exception("Can't find config file at ".$yamlPath);
|
|
|
|
}
|
|
|
|
self::$instance = new self($options);
|
|
|
|
self::$instance->file = $yamlfile;
|
2015-10-31 14:42:25 +00:00
|
|
|
}
|
2016-09-07 22:28:28 +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
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* Destroy singleton instance.
|
|
|
|
*
|
2016-08-01 11:29:13 +00:00
|
|
|
* @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
|
|
|
}
|