2015-10-31 15:42:25 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* Config class.
|
2016-08-01 13:29:13 +02:00
|
|
|
*/
|
2016-12-05 13:12:27 +01:00
|
|
|
|
2015-10-31 15:42:25 +01:00
|
|
|
namespace Alltube;
|
2016-03-30 01:49:08 +02:00
|
|
|
|
2015-10-31 15:42:25 +01:00
|
|
|
use Symfony\Component\Yaml\Yaml;
|
2016-03-30 01:49:08 +02:00
|
|
|
|
2015-10-31 15:42:25 +01:00
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* Manage config parameters.
|
2016-08-01 13:29:13 +02:00
|
|
|
*/
|
2016-03-30 01:49:08 +02:00
|
|
|
class Config
|
2015-10-31 15:42:25 +01:00
|
|
|
{
|
2016-08-01 13:29:13 +02:00
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* Singleton instance.
|
|
|
|
*
|
2016-08-01 13:29:13 +02:00
|
|
|
* @var Config
|
|
|
|
*/
|
2016-03-30 01:49:08 +02:00
|
|
|
private static $instance;
|
2015-10-31 15:42:25 +01:00
|
|
|
|
2016-08-01 13:29:13 +02:00
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* youtube-dl binary path.
|
|
|
|
*
|
2016-08-01 13:29:13 +02:00
|
|
|
* @var string
|
|
|
|
*/
|
2015-10-31 15:56:00 +01:00
|
|
|
public $youtubedl = 'vendor/rg3/youtube-dl/youtube_dl/__main__.py';
|
2016-08-01 13:29:13 +02:00
|
|
|
|
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* python binary path.
|
|
|
|
*
|
2016-08-01 13:29:13 +02:00
|
|
|
* @var string
|
|
|
|
*/
|
2015-10-31 15:42:25 +01:00
|
|
|
public $python = '/usr/bin/python';
|
2016-08-01 13:29:13 +02:00
|
|
|
|
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* youtube-dl parameters.
|
|
|
|
*
|
2016-08-01 13:29:13 +02:00
|
|
|
* @var array
|
|
|
|
*/
|
2017-05-31 00:48:50 +02:00
|
|
|
public $params = ['--no-warnings', '--ignore-errors', '--flat-playlist', '--restrict-filenames'];
|
2016-08-01 13:29:13 +02:00
|
|
|
|
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* Enable audio conversion.
|
|
|
|
*
|
2016-08-01 13:29:13 +02:00
|
|
|
* @var bool
|
|
|
|
*/
|
2015-10-31 15:42:25 +01:00
|
|
|
public $convert = false;
|
2016-08-01 13:29:13 +02:00
|
|
|
|
2018-01-24 23:30:24 +01:00
|
|
|
/**
|
|
|
|
* Enable advanced conversion mode.
|
|
|
|
*
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
public $convertAdvanced = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List of formats available in advanced conversion mode.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $convertAdvancedFormats = ['mp3', 'avi', 'flv', 'wav'];
|
|
|
|
|
2016-08-01 13:29:13 +02:00
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* avconv or ffmpeg binary path.
|
|
|
|
*
|
2016-08-01 13:29:13 +02:00
|
|
|
* @var string
|
|
|
|
*/
|
2015-11-21 20:54:38 +01:00
|
|
|
public $avconv = 'vendor/bin/ffmpeg';
|
2016-08-01 13:29:13 +02:00
|
|
|
|
2017-01-10 23:37:29 +01:00
|
|
|
/**
|
|
|
|
* Disable URL rewriting.
|
2017-01-10 23:39:58 +01:00
|
|
|
*
|
|
|
|
* @var bool
|
2017-01-10 23:37:29 +01:00
|
|
|
*/
|
|
|
|
public $uglyUrls = false;
|
|
|
|
|
2017-01-16 11:29:56 +01:00
|
|
|
/**
|
|
|
|
* Stream downloaded files trough server?
|
2017-01-16 12:11:37 +01:00
|
|
|
*
|
|
|
|
* @var bool
|
2017-01-16 11:29:56 +01:00
|
|
|
*/
|
|
|
|
public $stream = false;
|
|
|
|
|
2017-04-25 00:40:24 +02:00
|
|
|
/**
|
|
|
|
* Allow to remux video + audio?
|
|
|
|
*
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
public $remux = false;
|
|
|
|
|
2017-11-10 23:50:17 +01:00
|
|
|
/**
|
2017-11-10 23:52:04 +01:00
|
|
|
* MP3 bitrate when converting (in kbit/s).
|
2017-11-10 23:50:17 +01:00
|
|
|
*
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
public $audioBitrate = 128;
|
|
|
|
|
2017-12-09 23:16:48 +01:00
|
|
|
/**
|
|
|
|
* avconv/ffmpeg logging level.
|
2017-12-09 23:57:21 +01:00
|
|
|
* Must be one of these: quiet, panic, fatal, error, warning, info, verbose, debug.
|
2017-12-09 23:16:48 +01:00
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $avconvVerbosity = 'error';
|
|
|
|
|
2016-09-06 00:36:47 +02:00
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* YAML config file path.
|
|
|
|
*
|
2016-09-06 00:36:47 +02:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $file;
|
2016-08-19 01:07:51 +02:00
|
|
|
|
2015-10-31 15:50:32 +01:00
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* Config constructor.
|
2016-09-06 00:36:47 +02:00
|
|
|
*
|
2018-01-06 17:46:49 +01:00
|
|
|
* @param array $options Options (see `config/config.example.yml` for available options)
|
2015-10-31 15:50:32 +01:00
|
|
|
*/
|
2016-10-18 09:54:08 +02:00
|
|
|
public function __construct(array $options)
|
2015-10-31 15:50:32 +01:00
|
|
|
{
|
2016-10-18 09:54:08 +02:00
|
|
|
if (isset($options) && is_array($options)) {
|
|
|
|
foreach ($options as $option => $value) {
|
|
|
|
if (isset($this->$option) && isset($value)) {
|
|
|
|
$this->$option = $value;
|
2015-10-31 15:57:36 +01:00
|
|
|
}
|
2015-10-31 15:42:25 +01:00
|
|
|
}
|
|
|
|
}
|
2018-01-06 18:03:06 +01:00
|
|
|
$this->getEnv();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Override options from environement variables.
|
|
|
|
* Supported environment variables: CONVERT, PYTHON, AUDIO_BITRATE.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function getEnv()
|
|
|
|
{
|
|
|
|
foreach (['CONVERT', 'PYTHON', 'AUDIO_BITRATE'] as $var) {
|
|
|
|
$env = getenv($var);
|
|
|
|
if ($env) {
|
|
|
|
$prop = lcfirst(str_replace('_', '', ucwords(strtolower($var), '_')));
|
|
|
|
$this->$prop = $env;
|
|
|
|
}
|
2016-12-22 13:46:31 +01:00
|
|
|
}
|
2015-10-31 15:42:25 +01:00
|
|
|
}
|
|
|
|
|
2015-10-31 15:50:32 +01:00
|
|
|
/**
|
2016-10-18 09:54:08 +02:00
|
|
|
* Get Config singleton instance from YAML config file.
|
2016-02-28 23:04:53 +01:00
|
|
|
*
|
2016-09-06 00:36:47 +02:00
|
|
|
* @param string $yamlfile YAML config file name
|
|
|
|
*
|
2015-10-31 15:50:32 +01:00
|
|
|
* @return Config
|
|
|
|
*/
|
2017-05-15 07:25:14 +02:00
|
|
|
public static function getInstance($yamlfile = 'config/config.yml')
|
2015-10-31 15:50:32 +01:00
|
|
|
{
|
2016-10-18 09:54:08 +02:00
|
|
|
$yamlPath = __DIR__.'/../'.$yamlfile;
|
2016-08-19 01:07:51 +02:00
|
|
|
if (is_null(self::$instance) || self::$instance->file != $yamlfile) {
|
2016-10-18 09:54:08 +02:00
|
|
|
if (is_file($yamlfile)) {
|
|
|
|
$options = Yaml::parse(file_get_contents($yamlPath));
|
2017-05-15 07:25:14 +02:00
|
|
|
} elseif ($yamlfile == 'config/config.yml' || empty($yamlfile)) {
|
2016-10-18 09:54:08 +02:00
|
|
|
/*
|
|
|
|
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 15:42:25 +01:00
|
|
|
}
|
2016-09-07 22:28:28 +00:00
|
|
|
|
2016-03-30 01:49:08 +02:00
|
|
|
return self::$instance;
|
2015-10-31 15:42:25 +01:00
|
|
|
}
|
2016-07-30 12:40:49 +02:00
|
|
|
|
2016-08-01 13:29:13 +02:00
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* Destroy singleton instance.
|
|
|
|
*
|
2016-08-01 13:29:13 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
2016-07-30 12:40:49 +02:00
|
|
|
public static function destroyInstance()
|
|
|
|
{
|
|
|
|
self::$instance = null;
|
|
|
|
}
|
2015-10-31 15:42:25 +01:00
|
|
|
}
|