/** * Redirect to video file. * * @param Request $request PSR-7 request * @param Response $response PSR-7 response * * @return Response HTTP response */ public function redirect(Request $request, Response $response) { $params = $request->getQueryParams(); if (isset($params['url'])) { try { $url = $this->download->getURL($params['url'], $params['format']); return $response->withRedirect($url); } catch (\Exception $e) { $response->getBody()->write($e->getMessage()); return $response->withHeader('Content-Type', 'text/plain'); } } }
/** * Test getURL function errors. * * @param string $url URL * * @return void * @expectedException Exception * @dataProvider ErrorUrlProvider */ public function testGetURLError($url) { $this->download->getURL($url); }
/** * Redirect to video file * @return void */ static function redirect() { global $app; if (isset($_GET["url"])) { try { $video = VideoDownload::getURL($_GET["url"]); $app->redirect($video['url']); } catch (\Exception $e) { $app->response->headers->set('Content-Type', 'text/plain'); echo $e->getMessage(); } } }
/** * Test getURL function errors * * @param string $url URL * * @return void * @expectedException Exception * @dataProvider ErrorUrlProvider */ public function testGetURLError($url) { $videoURL = VideoDownload::getURL($url); }