Improve the way we test if a command can be ran (see #109)
This commit is contained in:
parent
ae99d20fd3
commit
a89b338060
1 changed files with 19 additions and 3 deletions
|
@ -220,7 +220,7 @@ class VideoDownload
|
||||||
*/
|
*/
|
||||||
private function getRtmpProcess(\stdClass $video)
|
private function getRtmpProcess(\stdClass $video)
|
||||||
{
|
{
|
||||||
if (!shell_exec('which '.$this->config->rtmpdump)) {
|
if (!$this->checkCommand([$this->config->rtmpdump, '--help'])) {
|
||||||
throw(new \Exception('Can\'t find rtmpdump'));
|
throw(new \Exception('Can\'t find rtmpdump'));
|
||||||
}
|
}
|
||||||
$builder = new ProcessBuilder(
|
$builder = new ProcessBuilder(
|
||||||
|
@ -240,6 +240,22 @@ class VideoDownload
|
||||||
return $builder->getProcess();
|
return $builder->getProcess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a command runs successfully
|
||||||
|
*
|
||||||
|
* @param array $command Command and arguments
|
||||||
|
*
|
||||||
|
* @return bool False if the command returns an error, true otherwise
|
||||||
|
*/
|
||||||
|
private function checkCommand(array $command)
|
||||||
|
{
|
||||||
|
$builder = ProcessBuilder::create($command);
|
||||||
|
$process = $builder->getProcess();
|
||||||
|
$process->run();
|
||||||
|
|
||||||
|
return $process->isSuccessful();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a process that runs avconv in order to convert a video to MP3.
|
* Get a process that runs avconv in order to convert a video to MP3.
|
||||||
*
|
*
|
||||||
|
@ -249,7 +265,7 @@ class VideoDownload
|
||||||
*/
|
*/
|
||||||
private function getAvconvMp3Process($url)
|
private function getAvconvMp3Process($url)
|
||||||
{
|
{
|
||||||
if (!shell_exec('which '.$this->config->avconv)) {
|
if (!$this->checkCommand([$this->config->avconv, '-version'])) {
|
||||||
throw(new \Exception('Can\'t find avconv or ffmpeg'));
|
throw(new \Exception('Can\'t find avconv or ffmpeg'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,7 +323,7 @@ class VideoDownload
|
||||||
*/
|
*/
|
||||||
public function getM3uStream(\stdClass $video)
|
public function getM3uStream(\stdClass $video)
|
||||||
{
|
{
|
||||||
if (!shell_exec('which '.$this->config->avconv)) {
|
if (!$this->checkCommand([$this->config->avconv, '-version'])) {
|
||||||
throw(new \Exception('Can\'t find avconv or ffmpeg'));
|
throw(new \Exception('Can\'t find avconv or ffmpeg'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue