From 2ebea7749b7240bbe6e3b1f3f50a45f9a5005e90 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Sun, 19 Mar 2017 12:27:08 +0100 Subject: [PATCH] Fix redirect when no format is specified --- controllers/FrontController.php | 12 +++++++----- tests/FrontControllerTest.php | 17 ++++++++++++++++- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/controllers/FrontController.php b/controllers/FrontController.php index 233be8c..84ef036 100644 --- a/controllers/FrontController.php +++ b/controllers/FrontController.php @@ -299,9 +299,6 @@ class FrontController */ private function getStream($url, $format, $response, $request, $password = null) { - if (!isset($format)) { - $format = 'best'; - } $video = $this->download->getJSON($url, $format, $password); if ($video->protocol == 'm3u8') { $stream = $this->download->getM3uStream($video); @@ -334,12 +331,17 @@ class FrontController public function redirect(Request $request, Response $response) { $params = $request->getQueryParams(); + if (isset($params['format'])) { + $format = $params['format']; + } else { + $format = $this->defaultFormat; + } if (isset($params['url'])) { try { if ($this->config->stream) { return $this->getStream( $params['url'], - $request->getParam('format'), + $format, $response, $request, $this->sessionSegment->getFlash($params['url']) @@ -347,7 +349,7 @@ class FrontController } else { $url = $this->download->getURL( $params['url'], - $request->getParam('format'), + $format, $this->sessionSegment->getFlash($params['url']) ); diff --git a/tests/FrontControllerTest.php b/tests/FrontControllerTest.php index c3b946e..efbed07 100644 --- a/tests/FrontControllerTest.php +++ b/tests/FrontControllerTest.php @@ -292,6 +292,19 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase $this->assertTrue($result->isRedirect()); } + /** + * Test the redirect() function with a specific format. + * @return void + */ + public function testRedirectWithFormat() + { + $result = $this->controller->redirect( + $this->request->withQueryParams(['url'=>'https://www.youtube.com/watch?v=M7IpKCZ47pU', 'format'=>'worst']), + $this->response + ); + $this->assertTrue($result->isRedirect()); + } + /** * Test the redirect() function with streams enabled. * @@ -317,7 +330,9 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase { $config = Config::getInstance(); $config->stream = true; - $result = $this->controller->redirect( + //We need to create a new controller instance in order to apply the custom config + $controller = new FrontController($this->container); + $result = $controller->redirect( $this->request->withQueryParams(['url'=>'https://twitter.com/verge/status/813055465324056576/video/1']), $this->response );