Improve the way we test if a command can be ran (see #109)

This commit is contained in:
Pierre Rudloff 2017-05-14 00:52:59 +02:00
parent ae99d20fd3
commit a89b338060

View file

@ -220,7 +220,7 @@ class VideoDownload
*/
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'));
}
$builder = new ProcessBuilder(
@ -240,6 +240,22 @@ class VideoDownload
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.
*
@ -249,7 +265,7 @@ class VideoDownload
*/
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'));
}
@ -307,7 +323,7 @@ class VideoDownload
*/
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'));
}