refactor: Reuse Video::getHttpResponse() where possible

This commit is contained in:
Pierre Rudloff 2019-04-21 22:38:27 +02:00
parent e93ab7ed13
commit 97a7830196
2 changed files with 4 additions and 12 deletions

View file

@ -562,11 +562,11 @@ class Video
*
* @return Response
*/
public function getHttpResponse()
public function getHttpResponse(array $headers = [])
{
$client = new Client();
$urls = $this->getUrl();
return $client->request('GET', $urls[0], ['stream' => true]);
return $client->request('GET', $urls[0], ['stream' => true, 'headers' => $headers]);
}
}

View file

@ -15,7 +15,6 @@ use Alltube\Video;
use Aura\Session\Segment;
use Aura\Session\SessionFactory;
use Exception;
use GuzzleHttp\Client;
use Psr\Container\ContainerInterface;
use Slim\Container;
use Slim\Http\Request;
@ -394,15 +393,8 @@ class FrontController
$response = $response->withHeader('Content-Type', 'video/'.$this->video->ext);
$body = new Stream($this->video->getM3uStream());
} else {
$client = new Client();
$stream = $client->request(
'GET',
$this->video->getUrl(),
[
'stream' => true,
'headers' => ['Range' => $request->getHeader('Range')],
]
);
$stream = $this->video->getHttpResponse(['Range' => $request->getHeader('Range')]);
$response = $response->withHeader('Content-Type', $stream->getHeader('Content-Type'));
$response = $response->withHeader('Content-Length', $stream->getHeader('Content-Length'));
$response = $response->withHeader('Accept-Ranges', $stream->getHeader('Accept-Ranges'));