From 1b4e96f5ef32eaf1f52584f30f9ed398163ae7d1 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Fri, 5 May 2017 00:25:08 +0200 Subject: [PATCH] Refactor FrontController::getStream() --- controllers/FrontController.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/controllers/FrontController.php b/controllers/FrontController.php index 1ac4969..bbcc358 100644 --- a/controllers/FrontController.php +++ b/controllers/FrontController.php @@ -329,23 +329,20 @@ class FrontController } elseif ($video->protocol == 'rtmp') { $stream = $this->download->getRtmpStream($video); $response = $response->withHeader('Content-Type', 'video/'.$video->ext); - if ($request->isGet()) { - $response = $response->withBody(new Stream($stream)); - } + $body = new Stream($stream); } elseif ($video->protocol == 'm3u8') { $stream = $this->download->getM3uStream($video); $response = $response->withHeader('Content-Type', 'video/'.$video->ext); - if ($request->isGet()) { - $response = $response->withBody(new Stream($stream)); - } + $body = new Stream($stream); } else { $client = new \GuzzleHttp\Client(); $stream = $client->request('GET', $video->url, ['stream' => true]); $response = $response->withHeader('Content-Type', $stream->getHeader('Content-Type')); $response = $response->withHeader('Content-Length', $stream->getHeader('Content-Length')); - if ($request->isGet()) { - $response = $response->withBody($stream->getBody()); - } + $body = $stream->getBody(); + } + if ($request->isGet()) { + $response = $response->withBody($body); } $response = $response->withHeader( 'Content-Disposition',