Applied fixes from StyleCI

This commit is contained in:
Pierre Rudloff 2016-09-07 22:28:28 +00:00 committed by StyleCI Bot
parent 6df1eccb9e
commit 13c3366e9d
6 changed files with 203 additions and 178 deletions

View file

@ -1,78 +1,88 @@
<?php
/**
* Config class
* Config class.
*/
namespace Alltube;
use Symfony\Component\Yaml\Yaml;
/**
* Manage config parameters
* Manage config parameters.
*/
class Config
{
/**
* Singleton instance
* Singleton instance.
*
* @var Config
*/
private static $instance;
/**
* youtube-dl binary path
* youtube-dl binary path.
*
* @var string
*/
public $youtubedl = 'vendor/rg3/youtube-dl/youtube_dl/__main__.py';
/**
* python binary path
* python binary path.
*
* @var string
*/
public $python = '/usr/bin/python';
/**
* youtube-dl parameters
* youtube-dl parameters.
*
* @var array
*/
public $params = array('--no-playlist', '--no-warnings', '-f best[protocol^=http]', '--playlist-end', 1);
public $params = ['--no-playlist', '--no-warnings', '-f best[protocol^=http]', '--playlist-end', 1];
/**
* Enable audio conversion
* Enable audio conversion.
*
* @var bool
*/
public $convert = false;
/**
* avconv or ffmpeg binary path
* avconv or ffmpeg binary path.
*
* @var string
*/
public $avconv = 'vendor/bin/ffmpeg';
/**
* rtmpdump binary path
* rtmpdump binary path.
*
* @var string
*/
public $rtmpdump = 'vendor/bin/rtmpdump';
/**
* curl binary path
* curl binary path.
*
* @var string
*/
public $curl = '/usr/bin/curl';
/**
* curl parameters
* curl parameters.
*
* @var array
*/
public $curl_params = array();
public $curl_params = [];
/**
* YAML config file path
* YAML config file path.
*
* @var string
*/
private $file;
/**
* Config constructor
* Config constructor.
*
* @param string $yamlfile YAML config file path
*/
@ -95,7 +105,7 @@ class Config
}
/**
* Get singleton instance
* Get singleton instance.
*
* @param string $yamlfile YAML config file name
*
@ -105,13 +115,15 @@ class Config
{
$yamlfile = __DIR__.'/../'.$yamlfile;
if (is_null(self::$instance) || self::$instance->file != $yamlfile) {
self::$instance = new Config($yamlfile);
self::$instance = new self($yamlfile);
}
return self::$instance;
}
/**
* Destroy singleton instance
* Destroy singleton instance.
*
* @return void
*/
public static function destroyInstance()

View file

@ -1,21 +1,19 @@
<?php
/**
* VideoDownload class
* VideoDownload class.
*/
namespace Alltube;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\ProcessBuilder;
use Chain\Chain;
use Symfony\Component\Process\ProcessBuilder;
/**
* Extract info about videos
* Extract info about videos.
*/
class VideoDownload
{
/**
* VideoDownload constructor
* VideoDownload constructor.
*/
public function __construct()
{
@ -23,31 +21,32 @@ class VideoDownload
$this->procBuilder = new ProcessBuilder();
$this->procBuilder->setPrefix(
array_merge(
array($this->config->python, $this->config->youtubedl),
[$this->config->python, $this->config->youtubedl],
$this->config->params
)
);
}
/**
* List all extractors
* List all extractors.
*
* @return string[] Extractors
* */
public function listExtractors()
{
$this->procBuilder->setArguments(
array(
'--list-extractors'
)
[
'--list-extractors',
]
);
$process = $this->procBuilder->getProcess();
$process->run();
return explode(PHP_EOL, trim($process->getOutput()));
}
/**
* Get all information about a video
* Get all information about a video.
*
* @param string $url URL of page
* @param string $format Format to use for the video
@ -57,10 +56,10 @@ class VideoDownload
public function getJSON($url, $format = null)
{
$this->procBuilder->setArguments(
array(
[
'--dump-json',
$url
)
$url,
]
);
if (isset($format)) {
$this->procBuilder->add('-f '.$format);
@ -75,7 +74,7 @@ class VideoDownload
}
/**
* Get URL of video from URL of page
* Get URL of video from URL of page.
*
* @param string $url URL of page
* @param string $format Format to use for the video
@ -85,10 +84,10 @@ class VideoDownload
public function getURL($url, $format = null)
{
$this->procBuilder->setArguments(
array(
[
'--get-url',
$url
)
$url,
]
);
if (isset($format)) {
$this->procBuilder->add('-f '.$format);
@ -103,7 +102,7 @@ class VideoDownload
}
/**
* Get filename of video file from URL of page
* Get filename of video file from URL of page.
*
* @param string $url URL of page
* @param string $format Format to use for the video
@ -113,10 +112,10 @@ class VideoDownload
public function getFilename($url, $format = null)
{
$this->procBuilder->setArguments(
array(
[
'--get-filename',
$url
)
$url,
]
);
if (isset($format)) {
$this->procBuilder->add('-f '.$format);
@ -131,7 +130,7 @@ class VideoDownload
}
/**
* Get filename of audio from URL of page
* Get filename of audio from URL of page.
*
* @param string $url URL of page
* @param string $format Format to use for the video
@ -151,7 +150,7 @@ class VideoDownload
}
/**
* Get audio stream of converted video
* Get audio stream of converted video.
*
* @param string $url URL of page
* @param string $format Format to use for the video
@ -172,14 +171,14 @@ class VideoDownload
$video->http_headers->{'User-Agent'}
);
$avconvProc = ProcessBuilder::create(
array(
[
$this->config->avconv,
'-v', 'quiet',
'-i', '-',
'-f', 'mp3',
'-vn',
'pipe:1'
)
'pipe:1',
]
);
if (parse_url($video->url, PHP_URL_SCHEME) == 'rtmp') {
@ -187,13 +186,13 @@ class VideoDownload
throw(new \Exception('Can\'t find rtmpdump'));
}
$builder = new ProcessBuilder(
array(
[
$this->config->rtmpdump,
'-q',
'-r',
$video->url,
'--pageUrl', $video->webpage_url
)
'--pageUrl', $video->webpage_url,
]
);
if (isset($video->player_url)) {
$builder->add('--swfVfy');
@ -226,19 +225,20 @@ class VideoDownload
$chain = new Chain(
ProcessBuilder::create(
array_merge(
array(
[
$this->config->curl,
'--silent',
'--location',
'--user-agent', $video->http_headers->{'User-Agent'},
$video->url
),
$video->url,
],
$this->config->curl_params
)
)
);
$chain->add('|', $avconvProc);
}
return popen($chain->getProcess()->getCommandLine(), 'r');
}
}