This commit is contained in:
Pierre Rudloff 2016-09-11 19:03:51 +02:00
parent dd67495ccb
commit 4b99f03e0d

View file

@ -107,7 +107,7 @@ class FrontController
if (isset($params['url'])) { if (isset($params['url'])) {
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);
} catch (\Exception $e) { } catch (\Exception $e) {
$response = $response->withHeader( $response = $response->withHeader(
'Content-Disposition', 'Content-Disposition',
@ -172,13 +172,14 @@ class FrontController
} }
$video = $this->download->getJSON($url, $format); $video = $this->download->getJSON($url, $format);
$client = new \GuzzleHttp\Client(); $client = new \GuzzleHttp\Client();
$stream = $client->request('GET', $video->url, array('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.'"');
$response = $response->withHeader('Content-Type', $stream->getHeader('Content-Type')); $response = $response->withHeader('Content-Type', $stream->getHeader('Content-Type'));
$response = $response->withHeader('Content-Length', $stream->getHeader('Content-Length')); $response = $response->withHeader('Content-Length', $stream->getHeader('Content-Length'));
if ($request->isGet()) { if ($request->isGet()) {
$response = $response->withBody($stream->getBody()); $response = $response->withBody($stream->getBody());
} }
return $response; return $response;
} }
@ -195,7 +196,7 @@ 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'], $params['format'], $response, $request);
} catch (\Exception $e) { } catch (\Exception $e) {
$response->getBody()->write($e->getMessage()); $response->getBody()->write($e->getMessage());