Alltube\Controller\FrontController::video PHP Method

video() public method

Dislay information about the video.
public video ( Slim\Http\Request $request, Slim\Http\Response $response ) : Slim\Http\Response
$request Slim\Http\Request PSR-7 request
$response Slim\Http\Response PSR-7 response
return Slim\Http\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'));
        }
    }