Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Merge branch 'release-3.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Rudloff committed Apr 20, 2021
2 parents 6ab19b6 + b902c90 commit eeda434
Show file tree
Hide file tree
Showing 35 changed files with 862 additions and 1,082 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# AllTube Download

[![Donate using Liberapay](https://liberapay.com/assets/widgets/donate.svg)](https://liberapay.com/Rudloff/donate)

HTML GUI for youtube-dl ([alltubedownload.net](http://alltubedownload.net/))

![Screenshot](img/screenshot.png "AllTube GUI screenshot")
Expand Down
29 changes: 26 additions & 3 deletions classes/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Alltube\Exception\ConfigException;
use Alltube\Exception\DependencyException;
use Alltube\Factory\ConfigFactory;
use Alltube\Factory\DebugBarFactory;
use Alltube\Factory\LocaleManagerFactory;
use Alltube\Factory\LoggerFactory;
use Alltube\Factory\SessionFactory;
Expand All @@ -16,6 +17,7 @@
use Alltube\Middleware\LinkHeaderMiddleware;
use Alltube\Middleware\LocaleMiddleware;
use Alltube\Middleware\RouterPathMiddleware;
use DebugBar\DebugBarException;
use Slim\Container;
use SmartyException;

Expand All @@ -26,6 +28,7 @@ class App extends \Slim\App
* @throws ConfigException
* @throws DependencyException
* @throws SmartyException
* @throws DebugBarException
*/
public function __construct()
{
Expand All @@ -34,6 +37,8 @@ public function __construct()
/** @var Container $container */
$container = $this->getContainer();

$container['root_path'] = $this->getRootPath();

// Config.
$container['config'] = ConfigFactory::create($container);

Expand All @@ -43,12 +48,17 @@ public function __construct()
// Locales.
$container['locale'] = LocaleManagerFactory::create($container);

// Smarty.
$container['view'] = ViewFactory::create($container);

// Logger.
$container['logger'] = LoggerFactory::create($container);

if ($container->get('config')->debug) {
// Debug bar.
$container['debugbar'] = DebugBarFactory::create($container);
}

// Smarty.
$container['view'] = ViewFactory::create($container);

// Middlewares.
$this->add(new LocaleMiddleware($container));
$this->add(new CspMiddleware($container));
Expand Down Expand Up @@ -102,4 +112,17 @@ public function __construct()
[$jsonController, 'json']
)->setName('json');
}

/**
* @return string|null
*/
private function getRootPath(): ?string
{
// realpath() can return false but we prefer using null.
if ($rootPath = realpath(__DIR__ . '/../')) {
return $rootPath;
}

return null;
}
}
8 changes: 4 additions & 4 deletions classes/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function __construct(array $options = [])
*
* @return string
*/
public static function addHttpToFormat(string $format)
public static function addHttpToFormat(string $format): string
{
$newFormat = [];
foreach (explode('/', $format) as $subformat) {
Expand Down Expand Up @@ -266,7 +266,7 @@ private function getEnv()
* @return Config
* @throws ConfigException
*/
public static function fromFile(string $file)
public static function fromFile(string $file): Config
{
if (is_file($file)) {
return new self(Yaml::parse(strval(file_get_contents($file))));
Expand All @@ -293,7 +293,7 @@ public function setOptions(array $options)
*
* @return Downloader
*/
public function getDownloader()
public function getDownloader(): Downloader
{
return new Downloader(
$this->youtubedl,
Expand All @@ -308,7 +308,7 @@ public function getDownloader()
/**
* @return string
*/
public function getAppVersion()
public function getAppVersion(): string
{
$version = PrettyVersions::getRootPackageVersion();

Expand Down
12 changes: 6 additions & 6 deletions classes/Controller/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
use Alltube\Library\Video;
use Alltube\LocaleManager;
use Aura\Session\Segment;
use Consolidation\Log\Logger;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use Slim\Http\Request;
use Slim\Http\Response;
use Slim\Router;
Expand Down Expand Up @@ -72,7 +72,7 @@ abstract class BaseController
protected $downloader;

/**
* @var Logger
* @var LoggerInterface
*/
protected $logger;

Expand Down Expand Up @@ -111,7 +111,7 @@ public function __construct(ContainerInterface $container)
*
* @return string format
*/
protected function getFormat(Request $request)
protected function getFormat(Request $request): string
{
$format = $request->getQueryParam('format');
if (!isset($format)) {
Expand All @@ -126,9 +126,9 @@ protected function getFormat(Request $request)
*
* @param Request $request PSR-7 request
*
* @return string Password
* @return string|null Password
*/
protected function getPassword(Request $request)
protected function getPassword(Request $request): ?string
{
$url = $request->getQueryParam('url');

Expand All @@ -151,7 +151,7 @@ protected function getPassword(Request $request)
*
* @return Response HTTP response
*/
protected function displayError(Request $request, Response $response, string $message)
protected function displayError(Request $request, Response $response, string $message): Response
{
$controller = new FrontController($this->container);

Expand Down
14 changes: 7 additions & 7 deletions classes/Controller/DownloadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class DownloadController extends BaseController
* @return Response HTTP response
* @throws AlltubeLibraryException
*/
public function download(Request $request, Response $response)
public function download(Request $request, Response $response): Response
{
$url = $request->getQueryParam('url');

Expand Down Expand Up @@ -99,7 +99,7 @@ public function download(Request $request, Response $response)
* @return Response HTTP response
* @throws AlltubeLibraryException
*/
private function getConvertedAudioResponse(Request $request, Response $response)
private function getConvertedAudioResponse(Request $request, Response $response): Response
{
$from = null;
$to = null;
Expand Down Expand Up @@ -135,7 +135,7 @@ private function getConvertedAudioResponse(Request $request, Response $response)
* @throws PasswordException
* @throws WrongPasswordException
*/
private function getAudioResponse(Request $request, Response $response)
private function getAudioResponse(Request $request, Response $response): Response
{
if (!empty($request->getQueryParam('from')) || !empty($request->getQueryParam('to'))) {
// Force convert when we need to seek.
Expand Down Expand Up @@ -174,7 +174,7 @@ private function getAudioResponse(Request $request, Response $response)
* @return Response HTTP response
* @throws AlltubeLibraryException
*/
private function getStream(Request $request, Response $response)
private function getStream(Request $request, Response $response): Response
{
if (isset($this->video->entries)) {
if ($this->config->convert && $request->getQueryParam('audio')) {
Expand Down Expand Up @@ -240,7 +240,7 @@ private function getStream(Request $request, Response $response)
* @return Response HTTP response
* @throws AlltubeLibraryException
*/
private function getRemuxStream(Request $request, Response $response)
private function getRemuxStream(Request $request, Response $response): Response
{
if (!$this->config->remux) {
throw new RemuxException('You need to enable remux mode to merge two formats.');
Expand All @@ -267,7 +267,7 @@ private function getRemuxStream(Request $request, Response $response)
* @return Response HTTP response
* @throws AlltubeLibraryException
*/
private function getDownloadResponse(Request $request, Response $response)
private function getDownloadResponse(Request $request, Response $response): Response
{
try {
$videoUrls = $this->video->getUrl();
Expand Down Expand Up @@ -306,7 +306,7 @@ private function getDownloadResponse(Request $request, Response $response)
* @throws YoutubedlException
* @throws PopenStreamException
*/
private function getConvertedResponse(Request $request, Response $response)
private function getConvertedResponse(Request $request, Response $response): Response
{
$response = $response->withHeader(
'Content-Disposition',
Expand Down
20 changes: 10 additions & 10 deletions classes/Controller/FrontController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function __construct(ContainerInterface $container)
*
* @return Response HTTP response
*/
public function index(Request $request, Response $response)
public function index(Request $request, Response $response): Response
{
$this->view->render(
$response,
Expand All @@ -78,7 +78,7 @@ public function index(Request $request, Response $response)
*
* @return Response
*/
public function locale(Request $request, Response $response, array $data)
public function locale(Request $request, Response $response, array $data): Response
{
$this->localeManager->setLocale(new Locale($data['locale']));

Expand All @@ -94,7 +94,7 @@ public function locale(Request $request, Response $response, array $data)
* @return Response HTTP response
* @throws AlltubeLibraryException
*/
public function extractors(Request $request, Response $response)
public function extractors(Request $request, Response $response): Response
{
$this->view->render(
$response,
Expand All @@ -119,7 +119,7 @@ public function extractors(Request $request, Response $response)
*
* @return Response HTTP response
*/
public function password(Request $request, Response $response)
public function password(Request $request, Response $response): Response
{
$this->view->render(
$response,
Expand Down Expand Up @@ -199,7 +199,7 @@ private function getInfoResponse(Request $request, Response $response)
* @return Response HTTP response
* @throws AlltubeLibraryException
*/
public function info(Request $request, Response $response)
public function info(Request $request, Response $response): Response
{
$url = $request->getQueryParam('url') ?: $request->getQueryParam('v');

Expand Down Expand Up @@ -228,7 +228,7 @@ public function info(Request $request, Response $response)
*
* @return Response HTTP response
*/
protected function displayError(Request $request, Response $response, string $message)
protected function displayError(Request $request, Response $response, string $message): Response
{
$this->view->render(
$response,
Expand All @@ -248,7 +248,7 @@ protected function displayError(Request $request, Response $response, string $me
* @param Response $response
* @return Response
*/
public function notFound(Request $request, Response $response)
public function notFound(Request $request, Response $response): Response
{
return $this->displayError($request, $response, $this->localeManager->t('Page not found'))
->withStatus(StatusCode::HTTP_NOT_FOUND);
Expand All @@ -259,7 +259,7 @@ public function notFound(Request $request, Response $response)
* @param Response $response
* @return Response
*/
public function notAllowed(Request $request, Response $response)
public function notAllowed(Request $request, Response $response): Response
{
return $this->displayError($request, $response, $this->localeManager->t('Method not allowed'))
->withStatus(StatusCode::HTTP_METHOD_NOT_ALLOWED);
Expand All @@ -274,7 +274,7 @@ public function notAllowed(Request $request, Response $response)
*
* @return Response HTTP response
*/
public function error(Request $request, Response $response, Throwable $error)
public function error(Request $request, Response $response, Throwable $error): Response
{
$this->logger->error($error);

Expand All @@ -285,7 +285,7 @@ public function error(Request $request, Response $response, Throwable $error)
$response = $cspMiddleware->applyHeader($response);

if ($this->config->debug) {
$renderer = new HtmlErrorRenderer(true);
$renderer = new HtmlErrorRenderer(true, null, null, $this->container->get('root_path'));
$exception = $renderer->render($error);

$response->getBody()->write($exception->getAsString());
Expand Down
2 changes: 1 addition & 1 deletion classes/Controller/JsonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class JsonController extends BaseController
* @return Response HTTP response
* @throws AlltubeLibraryException
*/
public function json(Request $request, Response $response)
public function json(Request $request, Response $response): Response
{
$url = $request->getQueryParam('url');

Expand Down
2 changes: 1 addition & 1 deletion classes/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static function handle(Throwable $e)

if (class_exists(HtmlErrorRenderer::class)) {
// If dev dependencies are loaded, we can use symfony/error-handler.
$renderer = new HtmlErrorRenderer(true);
$renderer = new HtmlErrorRenderer(true, null, null, dirname(__DIR__));
$exception = $renderer->render($e);

http_response_code($exception->getStatusCode());
Expand Down
4 changes: 2 additions & 2 deletions classes/Factory/ConfigFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class ConfigFactory
* @return Config
* @throws ConfigException
*/
public static function create(Container $container)
public static function create(Container $container): Config
{
$configPath = __DIR__ . '/../../config/config.yml';
$configPath = $container->get('root_path') . '/config/config.yml';
if (is_file($configPath)) {
$config = Config::fromFile($configPath);
} else {
Expand Down
48 changes: 48 additions & 0 deletions classes/Factory/DebugBarFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Alltube\Factory;

use DebugBar\DataCollector\ConfigCollector;
use DebugBar\DataCollector\MemoryCollector;
use DebugBar\DataCollector\MessagesCollector;
use DebugBar\DataCollector\PhpInfoCollector;
use DebugBar\DataCollector\RequestDataCollector;
use DebugBar\DebugBar;
use DebugBar\DebugBarException;
use Kitchenu\Debugbar\DataCollector\SlimRouteCollector;
use Slim\Container;

/**
* Class DebugBarFactory
* @package Alltube\Factory
*/
class DebugBarFactory
{

/**
* @param Container $container
* @return DebugBar
* @throws DebugBarException
*/
public static function create(Container $container): DebugBar
{
$debugBar = new DebugBar();

$requestCollector = new RequestDataCollector();
$configCollector = new ConfigCollector(get_object_vars($container->get('config')));

$debugBar->addCollector(new PhpInfoCollector())
->addCollector(new MessagesCollector())
->addCollector($requestCollector)
->addCollector(new MemoryCollector())
->addCollector($configCollector)
->addCollector(new SlimRouteCollector($container->get('router'), $container->get('request')));

$container->get('logger')->add('debugbar', $debugBar->getCollector('messages'));

$requestCollector->useHtmlVarDumper();
$configCollector->useHtmlVarDumper();

return $debugBar;
}
}
Loading

0 comments on commit eeda434

Please sign in to comment.