Fix redirect when no format is specified
This commit is contained in:
parent
9d4569244f
commit
2ebea7749b
2 changed files with 23 additions and 6 deletions
|
@ -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'])
|
||||
);
|
||||
|
||||
|
|
|
@ -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
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue