Refactor code
This commit is contained in:
parent
8090a8dc6e
commit
b0cdbd41ed
1 changed files with 71 additions and 52 deletions
|
@ -148,38 +148,12 @@ class VideoDownload
|
|||
}
|
||||
|
||||
/**
|
||||
* Get audio stream of converted video.
|
||||
*
|
||||
* @param string $url URL of page
|
||||
* @param string $format Format to use for the video
|
||||
*
|
||||
* @return resource popen stream
|
||||
* Get a process that runs rtmp in order to download a video
|
||||
* @param object $video Video object returned by youtube-dl
|
||||
* @return \Symfony\Component\Process\Process Process
|
||||
*/
|
||||
public function getAudioStream($url, $format)
|
||||
private function getRtmpProcess($video)
|
||||
{
|
||||
if (!shell_exec('which '.$this->config->avconv)) {
|
||||
throw(new \Exception('Can\'t find avconv or ffmpeg'));
|
||||
}
|
||||
|
||||
$video = $this->getJSON($url, $format);
|
||||
|
||||
//Vimeo needs a correct user-agent
|
||||
ini_set(
|
||||
'user_agent',
|
||||
$video->http_headers->{'User-Agent'}
|
||||
);
|
||||
$avconvProc = ProcessBuilder::create(
|
||||
[
|
||||
$this->config->avconv,
|
||||
'-v', 'quiet',
|
||||
'-i', '-',
|
||||
'-f', 'mp3',
|
||||
'-vn',
|
||||
'pipe:1',
|
||||
]
|
||||
);
|
||||
|
||||
if (parse_url($video->url, PHP_URL_SCHEME) == 'rtmp') {
|
||||
if (!shell_exec('which '.$this->config->rtmpdump)) {
|
||||
throw(new \Exception('Can\'t find rtmpdump'));
|
||||
}
|
||||
|
@ -214,14 +188,20 @@ class VideoDownload
|
|||
$builder->add('--app');
|
||||
$builder->add($video->app);
|
||||
}
|
||||
$chain = new Chain($builder->getProcess());
|
||||
$chain->add('|', $avconvProc);
|
||||
} else {
|
||||
return $builder->getProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a process that runs curl in order to download a video
|
||||
* @param object $video Video object returned by youtube-dl
|
||||
* @return \Symfony\Component\Process\Process Process
|
||||
*/
|
||||
private function getCurlProcess($video)
|
||||
{
|
||||
if (!shell_exec('which '.$this->config->curl)) {
|
||||
throw(new \Exception('Can\'t find curl'));
|
||||
}
|
||||
$chain = new Chain(
|
||||
ProcessBuilder::create(
|
||||
$builder = ProcessBuilder::create(
|
||||
array_merge(
|
||||
[
|
||||
$this->config->curl,
|
||||
|
@ -232,8 +212,47 @@ class VideoDownload
|
|||
],
|
||||
$this->config->curl_params
|
||||
)
|
||||
)
|
||||
);
|
||||
return $builder->getProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get audio stream of converted video.
|
||||
*
|
||||
* @param string $url URL of page
|
||||
* @param string $format Format to use for the video
|
||||
*
|
||||
* @return resource popen stream
|
||||
*/
|
||||
public function getAudioStream($url, $format)
|
||||
{
|
||||
if (!shell_exec('which '.$this->config->avconv)) {
|
||||
throw(new \Exception('Can\'t find avconv or ffmpeg'));
|
||||
}
|
||||
|
||||
$video = $this->getJSON($url, $format);
|
||||
|
||||
//Vimeo needs a correct user-agent
|
||||
ini_set(
|
||||
'user_agent',
|
||||
$video->http_headers->{'User-Agent'}
|
||||
);
|
||||
$avconvProc = ProcessBuilder::create(
|
||||
[
|
||||
$this->config->avconv,
|
||||
'-v', 'quiet',
|
||||
'-i', '-',
|
||||
'-f', 'mp3',
|
||||
'-vn',
|
||||
'pipe:1',
|
||||
]
|
||||
);
|
||||
|
||||
if (parse_url($video->url, PHP_URL_SCHEME) == 'rtmp') {
|
||||
$chain = new Chain($this->getRtmpProcess($video));
|
||||
$chain->add('|', $avconvProc);
|
||||
} else {
|
||||
$chain = new Chain($this->getCurlProcess($video));
|
||||
$chain->add('|', $avconvProc);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue