/**
* 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'));
}
}