ProcessBuilder is deprecated (fixes #144)
This commit is contained in:
parent
2e6fb8e7bd
commit
4c33c309a0
2 changed files with 47 additions and 53 deletions
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
namespace Alltube;
|
namespace Alltube;
|
||||||
|
|
||||||
use Symfony\Component\Process\ProcessBuilder;
|
use Symfony\Component\Process\Process;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class used to manage locales.
|
* Class used to manage locales.
|
||||||
|
@ -57,8 +57,7 @@ class LocaleManager
|
||||||
public function getSupportedLocales()
|
public function getSupportedLocales()
|
||||||
{
|
{
|
||||||
$return = [];
|
$return = [];
|
||||||
$builder = new ProcessBuilder(['locale', '-a']);
|
$process = new Process(['locale', '-a']);
|
||||||
$process = $builder->getProcess();
|
|
||||||
$process->run();
|
$process->run();
|
||||||
$installedLocales = explode(PHP_EOL, trim($process->getOutput()));
|
$installedLocales = explode(PHP_EOL, trim($process->getOutput()));
|
||||||
foreach ($this->supportedLocales as $supportedLocale) {
|
foreach ($this->supportedLocales as $supportedLocale) {
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
namespace Alltube;
|
namespace Alltube;
|
||||||
|
|
||||||
use Chain\Chain;
|
use Chain\Chain;
|
||||||
use Symfony\Component\Process\ProcessBuilder;
|
use Symfony\Component\Process\Process;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract info about videos.
|
* Extract info about videos.
|
||||||
|
@ -20,13 +20,6 @@ class VideoDownload
|
||||||
*/
|
*/
|
||||||
private $config;
|
private $config;
|
||||||
|
|
||||||
/**
|
|
||||||
* ProcessBuilder instance used to call Python.
|
|
||||||
*
|
|
||||||
* @var ProcessBuilder
|
|
||||||
*/
|
|
||||||
private $procBuilder;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* VideoDownload constructor.
|
* VideoDownload constructor.
|
||||||
*
|
*
|
||||||
|
@ -40,16 +33,27 @@ class VideoDownload
|
||||||
} else {
|
} else {
|
||||||
$this->config = Config::getInstance();
|
$this->config = Config::getInstance();
|
||||||
}
|
}
|
||||||
$this->procBuilder = new ProcessBuilder();
|
|
||||||
if (!is_file($this->config->youtubedl)) {
|
if (!is_file($this->config->youtubedl)) {
|
||||||
throw new \Exception("Can't find youtube-dl at ".$this->config->youtubedl);
|
throw new \Exception("Can't find youtube-dl at ".$this->config->youtubedl);
|
||||||
} elseif (!$this->checkCommand([$this->config->python, '--version'])) {
|
} elseif (!$this->checkCommand([$this->config->python, '--version'])) {
|
||||||
throw new \Exception("Can't find Python at ".$this->config->python);
|
throw new \Exception("Can't find Python at ".$this->config->python);
|
||||||
}
|
}
|
||||||
$this->procBuilder->setPrefix(
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a youtube-dl process with the specified arguments
|
||||||
|
*
|
||||||
|
* @param string[] $arguments Arguments
|
||||||
|
*
|
||||||
|
* @return Process
|
||||||
|
*/
|
||||||
|
private function getProcess(array $arguments)
|
||||||
|
{
|
||||||
|
return new Process(
|
||||||
array_merge(
|
array_merge(
|
||||||
[$this->config->python, $this->config->youtubedl],
|
[$this->config->python, $this->config->youtubedl],
|
||||||
$this->config->params
|
$this->config->params,
|
||||||
|
$arguments
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -80,24 +84,21 @@ class VideoDownload
|
||||||
*/
|
*/
|
||||||
private function getProp($url, $format = null, $prop = 'dump-json', $password = null)
|
private function getProp($url, $format = null, $prop = 'dump-json', $password = null)
|
||||||
{
|
{
|
||||||
$this->procBuilder->setArguments(
|
$arguments = [
|
||||||
[
|
|
||||||
'--'.$prop,
|
'--'.$prop,
|
||||||
$url,
|
$url
|
||||||
]
|
];
|
||||||
);
|
|
||||||
if (isset($format)) {
|
if (isset($format)) {
|
||||||
$this->procBuilder->add('-f '.$format);
|
$arguments[] = '-f '.$format;
|
||||||
}
|
}
|
||||||
if (isset($password)) {
|
if (isset($password)) {
|
||||||
$this->procBuilder->add('--video-password');
|
$arguments[] = '--video-password';
|
||||||
$this->procBuilder->add($password);
|
$arguments[] = $password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$process = $this->getProcess($arguments);
|
||||||
//This is needed by the openload extractor because it runs PhantomJS
|
//This is needed by the openload extractor because it runs PhantomJS
|
||||||
$this->procBuilder->setEnv('QT_QPA_PLATFORM', 'offscreen');
|
$process->setEnv(['QT_QPA_PLATFORM'=>'offscreen']);
|
||||||
|
|
||||||
$process = $this->procBuilder->getProcess();
|
|
||||||
$process->run();
|
$process->run();
|
||||||
if (!$process->isSuccessful()) {
|
if (!$process->isSuccessful()) {
|
||||||
$errorOutput = trim($process->getErrorOutput());
|
$errorOutput = trim($process->getErrorOutput());
|
||||||
|
@ -196,15 +197,18 @@ class VideoDownload
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add options to a process builder running rtmp.
|
* Return arguments used to run rtmp for a specific video.
|
||||||
*
|
*
|
||||||
* @param ProcessBuilder $builder Process builder
|
|
||||||
* @param object $video Video object returned by youtube-dl
|
* @param object $video Video object returned by youtube-dl
|
||||||
*
|
*
|
||||||
* @return ProcessBuilder
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function addOptionsToRtmpProcess(ProcessBuilder $builder, $video)
|
private function getRtmpProcessArguments(\stdClass $video)
|
||||||
{
|
{
|
||||||
|
$arguments = [
|
||||||
|
$this->config->rtmpdump,
|
||||||
|
'-q',
|
||||||
|
];
|
||||||
foreach ([
|
foreach ([
|
||||||
'url' => 'rtmp',
|
'url' => 'rtmp',
|
||||||
'webpage_url' => 'pageUrl',
|
'webpage_url' => 'pageUrl',
|
||||||
|
@ -214,12 +218,12 @@ class VideoDownload
|
||||||
'app' => 'app',
|
'app' => 'app',
|
||||||
] as $property => $option) {
|
] as $property => $option) {
|
||||||
if (isset($video->{$property})) {
|
if (isset($video->{$property})) {
|
||||||
$builder->add('--'.$option);
|
$arguments[] = '--'.$option;
|
||||||
$builder->add($video->{$property});
|
$arguments[] = $video->{$property};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $builder;
|
return $arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -236,21 +240,15 @@ class VideoDownload
|
||||||
if (!$this->checkCommand([$this->config->rtmpdump, '--help'])) {
|
if (!$this->checkCommand([$this->config->rtmpdump, '--help'])) {
|
||||||
throw(new \Exception('Can\'t find rtmpdump'));
|
throw(new \Exception('Can\'t find rtmpdump'));
|
||||||
}
|
}
|
||||||
$builder = new ProcessBuilder(
|
$arguments = $this->getRtmpProcessArguments($video);
|
||||||
[
|
|
||||||
$this->config->rtmpdump,
|
|
||||||
'-q',
|
|
||||||
]
|
|
||||||
);
|
|
||||||
$builder = $this->addOptionsToRtmpProcess($builder, $video);
|
|
||||||
if (isset($video->rtmp_conn)) {
|
if (isset($video->rtmp_conn)) {
|
||||||
foreach ($video->rtmp_conn as $conn) {
|
foreach ($video->rtmp_conn as $conn) {
|
||||||
$builder->add('--conn');
|
$arguments[] = '--conn';
|
||||||
$builder->add($conn);
|
$arguments[] = $conn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $builder->getProcess();
|
return new Process($arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -262,8 +260,7 @@ class VideoDownload
|
||||||
*/
|
*/
|
||||||
private function checkCommand(array $command)
|
private function checkCommand(array $command)
|
||||||
{
|
{
|
||||||
$builder = ProcessBuilder::create($command);
|
$process = new Process($command);
|
||||||
$process = $builder->getProcess();
|
|
||||||
$process->run();
|
$process->run();
|
||||||
|
|
||||||
return $process->isSuccessful();
|
return $process->isSuccessful();
|
||||||
|
@ -299,9 +296,7 @@ class VideoDownload
|
||||||
$arguments[] = $this->getProp(null, null, 'dump-user-agent');
|
$arguments[] = $this->getProp(null, null, 'dump-user-agent');
|
||||||
}
|
}
|
||||||
|
|
||||||
$builder = ProcessBuilder::create($arguments);
|
return new Process($arguments);
|
||||||
|
|
||||||
return $builder->getProcess();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -358,7 +353,7 @@ class VideoDownload
|
||||||
throw(new \Exception('Can\'t find avconv or ffmpeg'));
|
throw(new \Exception('Can\'t find avconv or ffmpeg'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$procBuilder = ProcessBuilder::create(
|
$process = new Process(
|
||||||
[
|
[
|
||||||
$this->config->avconv,
|
$this->config->avconv,
|
||||||
'-v', 'quiet',
|
'-v', 'quiet',
|
||||||
|
@ -371,7 +366,7 @@ class VideoDownload
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
$stream = popen($procBuilder->getProcess()->getCommandLine(), 'r');
|
$stream = popen($process->getCommandLine(), 'r');
|
||||||
if (!is_resource($stream)) {
|
if (!is_resource($stream)) {
|
||||||
throw new \Exception('Could not open popen stream.');
|
throw new \Exception('Could not open popen stream.');
|
||||||
}
|
}
|
||||||
|
@ -390,7 +385,7 @@ class VideoDownload
|
||||||
*/
|
*/
|
||||||
public function getRemuxStream(array $urls)
|
public function getRemuxStream(array $urls)
|
||||||
{
|
{
|
||||||
$procBuilder = ProcessBuilder::create(
|
$process = new Process(
|
||||||
[
|
[
|
||||||
$this->config->avconv,
|
$this->config->avconv,
|
||||||
'-v', 'quiet',
|
'-v', 'quiet',
|
||||||
|
@ -404,7 +399,7 @@ class VideoDownload
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
$stream = popen($procBuilder->getProcess()->getCommandLine(), 'r');
|
$stream = popen($process->getCommandLine(), 'r');
|
||||||
if (!is_resource($stream)) {
|
if (!is_resource($stream)) {
|
||||||
throw new \Exception('Could not open popen stream.');
|
throw new \Exception('Could not open popen stream.');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue