Add suport for passwords with streams

This commit is contained in:
Pierre Rudloff 2016-12-26 13:23:47 +01:00
parent 342dad38e6
commit 759f01ffd6

View file

@ -153,7 +153,7 @@ class FrontController
} }
if (isset($params['audio'])) { if (isset($params['audio'])) {
try { try {
return $this->getStream($params['url'], 'mp3[protocol^=http]', $response, $request); return $this->getStream($params['url'], 'mp3[protocol^=http]', $response, $request, $password);
} catch (PasswordException $e) { } catch (PasswordException $e) {
return $this->password($request, $response); return $this->password($request, $response);
} catch (\Exception $e) { } catch (\Exception $e) {
@ -217,12 +217,12 @@ class FrontController
return $response->withStatus(500); return $response->withStatus(500);
} }
private function getStream($url, $format, $response, $request) private function getStream($url, $format, $response, $request, $password = null)
{ {
if (!isset($format)) { if (!isset($format)) {
$format = 'best'; $format = 'best';
} }
$video = $this->download->getJSON($url, $format); $video = $this->download->getJSON($url, $format, $password);
$client = new \GuzzleHttp\Client(); $client = new \GuzzleHttp\Client();
$stream = $client->request('GET', $video->url, ['stream' => true]); $stream = $client->request('GET', $video->url, ['stream' => true]);
$response = $response->withHeader('Content-Disposition', 'attachment; filename="'.$video->_filename.'"'); $response = $response->withHeader('Content-Disposition', 'attachment; filename="'.$video->_filename.'"');
@ -248,7 +248,13 @@ class FrontController
$params = $request->getQueryParams(); $params = $request->getQueryParams();
if (isset($params['url'])) { if (isset($params['url'])) {
try { try {
return $this->getStream($params['url'], $params['format'], $response, $request); return $this->getStream(
$params['url'],
$request->getParam('format'),
$response,
$request,
$this->sessionSegment->getFlash($params['url'])
);
} catch (PasswordException $e) { } catch (PasswordException $e) {
return $response->withRedirect( return $response->withRedirect(
$this->container->get('router')->pathFor('video').'?url='.urlencode($params['url']) $this->container->get('router')->pathFor('video').'?url='.urlencode($params['url'])