style: Declare imported classes at the top of the file
This commit is contained in:
parent
33530eff4d
commit
04fe43a1ca
12 changed files with 81 additions and 63 deletions
|
@ -10,11 +10,16 @@ use Alltube\Locale;
|
|||
use Alltube\LocaleManager;
|
||||
use Alltube\PasswordException;
|
||||
use Alltube\VideoDownload;
|
||||
use Aura\Session\Segment;
|
||||
use Aura\Session\SessionFactory;
|
||||
use Exception;
|
||||
use GuzzleHttp\Client;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Slim\Container;
|
||||
use Slim\Http\Request;
|
||||
use Slim\Http\Response;
|
||||
use Slim\Http\Stream;
|
||||
use Slim\Views\Smarty;
|
||||
|
||||
/**
|
||||
* Main controller.
|
||||
|
@ -45,14 +50,14 @@ class FrontController
|
|||
/**
|
||||
* Session segment used to store session variables.
|
||||
*
|
||||
* @var \Aura\Session\Segment
|
||||
* @var Segment
|
||||
*/
|
||||
private $sessionSegment;
|
||||
|
||||
/**
|
||||
* Smarty view.
|
||||
*
|
||||
* @var \Slim\Views\Smarty
|
||||
* @var Smarty
|
||||
*/
|
||||
private $view;
|
||||
|
||||
|
@ -88,9 +93,9 @@ class FrontController
|
|||
$this->container = $container;
|
||||
$this->view = $this->container->get('view');
|
||||
$this->localeManager = $this->container->get('locale');
|
||||
$session_factory = new \Aura\Session\SessionFactory();
|
||||
$session_factory = new SessionFactory();
|
||||
$session = $session_factory->newInstance($cookies);
|
||||
$this->sessionSegment = $session->getSegment('Alltube\Controller\FrontController');
|
||||
$this->sessionSegment = $session->getSegment(self::class);
|
||||
if ($this->config->stream) {
|
||||
$this->defaultFormat = 'best';
|
||||
}
|
||||
|
@ -214,7 +219,7 @@ class FrontController
|
|||
}
|
||||
} catch (PasswordException $e) {
|
||||
return $this->password($request, $response);
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
$response = $response->withHeader(
|
||||
'Content-Disposition',
|
||||
'attachment; filename="'.
|
||||
|
@ -311,13 +316,13 @@ class FrontController
|
|||
/**
|
||||
* Display an error page.
|
||||
*
|
||||
* @param Request $request PSR-7 request
|
||||
* @param Response $response PSR-7 response
|
||||
* @param \Exception $exception Error to display
|
||||
* @param Request $request PSR-7 request
|
||||
* @param Response $response PSR-7 response
|
||||
* @param Exception $exception Error to display
|
||||
*
|
||||
* @return Response HTTP response
|
||||
*/
|
||||
public function error(Request $request, Response $response, \Exception $exception)
|
||||
public function error(Request $request, Response $response, Exception $exception)
|
||||
{
|
||||
$this->view->render(
|
||||
$response,
|
||||
|
@ -366,7 +371,7 @@ class FrontController
|
|||
$response = $response->withHeader('Content-Type', 'video/'.$video->ext);
|
||||
$body = new Stream($stream);
|
||||
} else {
|
||||
$client = new \GuzzleHttp\Client();
|
||||
$client = new 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'));
|
||||
|
@ -397,7 +402,7 @@ class FrontController
|
|||
private function getRemuxStream(array $urls, $format, Response $response, Request $request)
|
||||
{
|
||||
if (!$this->config->remux) {
|
||||
throw new \Exception(_('You need to enable remux mode to merge two formats.'));
|
||||
throw new Exception(_('You need to enable remux mode to merge two formats.'));
|
||||
}
|
||||
$stream = $this->download->getRemuxStream($urls);
|
||||
$response = $response->withHeader('Content-Type', 'video/x-matroska');
|
||||
|
@ -464,7 +469,7 @@ class FrontController
|
|||
);
|
||||
} else {
|
||||
if (empty($videoUrls[0])) {
|
||||
throw new \Exception(_("Can't find URL of video."));
|
||||
throw new Exception(_("Can't find URL of video."));
|
||||
}
|
||||
|
||||
return $response->withRedirect($videoUrls[0]);
|
||||
|
@ -533,7 +538,7 @@ class FrontController
|
|||
return $response->withRedirect(
|
||||
$this->container->get('router')->pathFor('video').'?url='.urlencode($params['url'])
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
$response->getBody()->write($e->getMessage());
|
||||
|
||||
return $response->withHeader('Content-Type', 'text/plain')->withStatus(500);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue