public getAudioStream ( string $url, string $format ) : resource | ||
$url | string | URL of page |
$format | string | 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') {
$process = $this->getRtmpProcess($video);
} else {
$process = $this->getCurlProcess($video);
}
$chain = new Chain($process);
$chain->add('|', $avconvProc);
return popen($chain->getProcess()->getCommandLine(), 'r');
}
/** * Test getAudioStream function without curl or rtmpdump. * * @param string $url URL * @param string $format Format * * @return void * @expectedException Exception * @dataProvider urlProvider */ public function testGetAudioStreamCurlError($url, $format) { $config = \Alltube\Config::getInstance(); $config->curl = 'foobar'; $config->rtmpdump = 'foobar'; $this->download->getAudioStream($url, $format); }