getAudioStream() public method

Get audio stream of converted video.
public getAudioStream ( string $url, string $format ) : resource
$url string URL of page
$format string Format to use for the video
return resource popen stream
Ejemplo n.º 1
0
 /**
  * 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);
 }
Ejemplo n.º 2
0
 /**
  * Dislay information about the video.
  *
  * @param Request  $request  PSR-7 request
  * @param Response $response PSR-7 response
  *
  * @return Response HTTP response
  */
 public function video(Request $request, Response $response)
 {
     $params = $request->getQueryParams();
     $this->config = Config::getInstance();
     if (isset($params['url'])) {
         if (isset($params['audio'])) {
             try {
                 $url = $this->download->getURL($params['url'], 'mp3[protocol^=http]');
                 return $response->withRedirect($url);
             } catch (\Exception $e) {
                 $response = $response->withHeader('Content-Disposition', 'attachment; filename="' . $this->download->getAudioFilename($params['url'], 'bestaudio/best') . '"');
                 $response = $response->withHeader('Content-Type', 'audio/mpeg');
                 if ($request->isGet()) {
                     $process = $this->download->getAudioStream($params['url'], 'bestaudio/best');
                     $response = $response->withBody(new Stream($process));
                 }
                 return $response;
             }
         } else {
             $video = $this->download->getJSON($params['url']);
             if ($this->container instanceof Container) {
                 $this->container->view->render($response, 'video.tpl', ['video' => $video, 'class' => 'video', 'title' => $video->title, 'description' => 'Download "' . $video->title . '" from ' . $video->extractor_key]);
             }
         }
     } else {
         return $response->withRedirect($this->container->get('router')->pathFor('index'));
     }
 }