/** * 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')); } }
/** * Test getAudioFilename function. * * @param string $url URL * @param string $format Format * @param string $filename Filename * @param string $domain Domain * @param string $audioFilename MP3 audio file name * * @return void * @dataProvider urlProvider */ public function testGetAudioFilename($url, $format, $filename, $domain, $audioFilename) { $videoFilename = $this->download->getAudioFilename($url, $format); $this->assertEquals($videoFilename, $audioFilename); }