From 96a75cbf1416eeb3bc46da43b88533dbe9031b41 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Wed, 15 Jul 2020 22:39:46 +0200 Subject: [PATCH] =?UTF-8?q?Log=20youtube-dl=20and=20ffmpeg=20commands=20(f?= =?UTF-8?q?ixes=C2=A0#297)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- classes/Controller/BaseController.php | 7 + classes/LoggerFactory.php | 33 ++ composer.json | 3 +- composer.lock | 620 +++++++++++++------------- index.php | 4 + tests/ControllerTest.php | 2 + 6 files changed, 359 insertions(+), 310 deletions(-) create mode 100644 classes/LoggerFactory.php diff --git a/classes/Controller/BaseController.php b/classes/Controller/BaseController.php index 05d3eb2..30a157c 100644 --- a/classes/Controller/BaseController.php +++ b/classes/Controller/BaseController.php @@ -12,6 +12,7 @@ use Alltube\Library\Video; use Alltube\LocaleManager; use Alltube\SessionManager; use Aura\Session\Segment; +use Consolidation\Log\Logger; use Psr\Container\ContainerInterface; use Slim\Http\Request; use Slim\Http\Response; @@ -70,6 +71,11 @@ abstract class BaseController */ protected $downloader; + /** + * @var Logger + */ + protected $logger; + /** * BaseController constructor. * @@ -83,6 +89,7 @@ abstract class BaseController $this->sessionSegment = $session->getSegment(self::class); $this->localeManager = $this->container->get('locale'); $this->downloader = $this->config->getDownloader(); + $this->downloader->setLogger($this->container->get('logger')); if (!$this->config->stream) { // Force HTTP if stream is not enabled. diff --git a/classes/LoggerFactory.php b/classes/LoggerFactory.php new file mode 100644 index 0000000..f0c71f6 --- /dev/null +++ b/classes/LoggerFactory.php @@ -0,0 +1,33 @@ +debug) { + $verbosity = ConsoleOutput::VERBOSITY_DEBUG; + } else { + $verbosity = ConsoleOutput::VERBOSITY_NORMAL; + } + + $logger = new Logger(new ConsoleOutput($verbosity)); + $logger->setLogOutputStyler(new LogOutputStyler()); + + return $logger; + } +} diff --git a/composer.json b/composer.json index d3c6d09..09f755a 100644 --- a/composer.json +++ b/composer.json @@ -23,12 +23,13 @@ "ext-json": "*", "aura/session": "^2.1", "barracudanetworks/archivestream-php": "^1.0", + "consolidation/log": "^2.0", "jawira/case-converter": "^3.4", "jean85/pretty-package-versions": "^1.3", "mathmarques/smarty-view": "^1.1", "npm-asset/open-sans-fontface": "^1.4", "rinvex/countries": "^6.1", - "rudloff/alltube-library": "^0.1.0", + "rudloff/alltube-library": "dev-develop", "symfony/finder": "^5.0", "symfony/translation": "^4.0", "symfony/yaml": "^4.0", diff --git a/composer.lock b/composer.lock index d83a5b2..2261130 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "2ca44dcc718001c0bbcbd4e59c1136b8", + "content-hash": "d0a5c7e93a6d08ce781d72a85dff85ab", "packages": [ { "name": "aura/session", @@ -163,6 +163,67 @@ "description": "Composer plugin that provides efficient querying for installed package versions (no runtime IO)", "time": "2020-06-19T07:59:31+00:00" }, + { + "name": "consolidation/log", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/consolidation/log.git", + "reference": "ba0bf6af1fbd09ed4dc18fc2f27b12ceff487cbf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/consolidation/log/zipball/ba0bf6af1fbd09ed4dc18fc2f27b12ceff487cbf", + "reference": "ba0bf6af1fbd09ed4dc18fc2f27b12ceff487cbf", + "shasum": "" + }, + "require": { + "php": ">=7.1.3", + "psr/log": "^1.0", + "symfony/console": "^4|^5" + }, + "require-dev": { + "g1a/composer-test-scenarios": "^3", + "php-coveralls/php-coveralls": "^2.2", + "phpunit/phpunit": "^6", + "squizlabs/php_codesniffer": "^3" + }, + "type": "library", + "extra": { + "scenarios": { + "symfony4": { + "require-dev": { + "symfony/console": "^4" + }, + "config": { + "platform": { + "php": "7.1.3" + } + } + } + }, + "branch-alias": { + "dev-master": "2.x-dev" + } + }, + "autoload": { + "psr-4": { + "Consolidation\\Log\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Greg Anderson", + "email": "greg.1.anderson@greenknowe.org" + } + ], + "description": "Improved Psr-3 / Psr\\Log logger based on Symfony Console components.", + "time": "2020-05-27T17:06:13+00:00" + }, { "name": "guzzlehttp/guzzle", "version": "6.5.5", @@ -724,6 +785,53 @@ ], "time": "2016-08-06T14:39:51+00:00" }, + { + "name": "psr/log", + "version": "1.1.3", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "0f73288fd15629204f9d42b7055f72dacbe811fc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/0f73288fd15629204f9d42b7055f72dacbe811fc", + "reference": "0f73288fd15629204f9d42b7055f72dacbe811fc", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "Psr/Log/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "time": "2020-03-23T09:12:05+00:00" + }, { "name": "ralouphie/getallheaders", "version": "3.0.3", @@ -844,21 +952,22 @@ }, { "name": "rudloff/alltube-library", - "version": "0.1.0", + "version": "dev-develop", "source": { "type": "git", "url": "https://github.com/Rudloff/alltube-library.git", - "reference": "09b47e0cf3157a79724177d6cadac8cee8cae588" + "reference": "0413427bbed7b02a2971b1716bf36c66924a205f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Rudloff/alltube-library/zipball/09b47e0cf3157a79724177d6cadac8cee8cae588", - "reference": "09b47e0cf3157a79724177d6cadac8cee8cae588", + "url": "https://api.github.com/repos/Rudloff/alltube-library/zipball/0413427bbed7b02a2971b1716bf36c66924a205f", + "reference": "0413427bbed7b02a2971b1716bf36c66924a205f", "shasum": "" }, "require": { "ext-json": "*", "guzzlehttp/guzzle": "^6.5", + "psr/log": "^1.1", "symfony/process": "^4.0|^5.0" }, "require-dev": { @@ -871,8 +980,7 @@ "type": "library", "autoload": { "psr-4": { - "Alltube\\Library\\": "classes/", - "Alltube\\Library\\Exception\\": "classes/exceptions/" + "Alltube\\Library\\": "classes/" } }, "notification-url": "https://packagist.org/downloads/", @@ -881,7 +989,7 @@ ], "description": "PHP wrapper for youtube-dl", "homepage": "http://alltubedownload.net/", - "time": "2020-06-21T12:25:10+00:00" + "time": "2020-07-15T20:34:36+00:00" }, { "name": "slim/slim", @@ -1009,6 +1117,82 @@ ], "time": "2018-09-12T20:54:16+00:00" }, + { + "name": "symfony/console", + "version": "v5.0.8", + "source": { + "type": "git", + "url": "https://github.com/symfony/console.git", + "reference": "5fa1caadc8cdaa17bcfb25219f3b53fe294a9935" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/console/zipball/5fa1caadc8cdaa17bcfb25219f3b53fe294a9935", + "reference": "5fa1caadc8cdaa17bcfb25219f3b53fe294a9935", + "shasum": "" + }, + "require": { + "php": "^7.2.5", + "symfony/polyfill-mbstring": "~1.0", + "symfony/polyfill-php73": "^1.8", + "symfony/service-contracts": "^1.1|^2" + }, + "conflict": { + "symfony/dependency-injection": "<4.4", + "symfony/event-dispatcher": "<4.4", + "symfony/lock": "<4.4", + "symfony/process": "<4.4" + }, + "provide": { + "psr/log-implementation": "1.0" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "^4.4|^5.0", + "symfony/dependency-injection": "^4.4|^5.0", + "symfony/event-dispatcher": "^4.4|^5.0", + "symfony/lock": "^4.4|^5.0", + "symfony/process": "^4.4|^5.0", + "symfony/var-dumper": "^4.4|^5.0" + }, + "suggest": { + "psr/log": "For using the console logger", + "symfony/event-dispatcher": "", + "symfony/lock": "", + "symfony/process": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Console\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Console Component", + "homepage": "https://symfony.com", + "time": "2020-03-30T11:42:42+00:00" + }, { "name": "symfony/finder", "version": "v5.0.8", @@ -1292,6 +1476,64 @@ ], "time": "2020-05-12T16:47:27+00:00" }, + { + "name": "symfony/polyfill-php73", + "version": "v1.17.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php73.git", + "reference": "a760d8964ff79ab9bf057613a5808284ec852ccc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/a760d8964ff79ab9bf057613a5808284ec852ccc", + "reference": "a760d8964ff79ab9bf057613a5808284ec852ccc", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.17-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php73\\": "" + }, + "files": [ + "bootstrap.php" + ], + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "time": "2020-05-12T16:47:27+00:00" + }, { "name": "symfony/process", "version": "v4.4.10", @@ -1341,6 +1583,64 @@ "homepage": "https://symfony.com", "time": "2020-05-30T20:06:45+00:00" }, + { + "name": "symfony/service-contracts", + "version": "v2.0.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/service-contracts.git", + "reference": "144c5e51266b281231e947b51223ba14acf1a749" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/service-contracts/zipball/144c5e51266b281231e947b51223ba14acf1a749", + "reference": "144c5e51266b281231e947b51223ba14acf1a749", + "shasum": "" + }, + "require": { + "php": "^7.2.5", + "psr/container": "^1.0" + }, + "suggest": { + "symfony/service-implementation": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Contracts\\Service\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Generic abstractions related to writing services", + "homepage": "https://symfony.com", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "time": "2019-11-18T17:27:11+00:00" + }, { "name": "symfony/translation", "version": "v4.4.0", @@ -1716,67 +2016,6 @@ "description": "Provide configuration services for a commandline tool.", "time": "2020-05-27T17:11:23+00:00" }, - { - "name": "consolidation/log", - "version": "2.0.1", - "source": { - "type": "git", - "url": "https://github.com/consolidation/log.git", - "reference": "ba0bf6af1fbd09ed4dc18fc2f27b12ceff487cbf" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/consolidation/log/zipball/ba0bf6af1fbd09ed4dc18fc2f27b12ceff487cbf", - "reference": "ba0bf6af1fbd09ed4dc18fc2f27b12ceff487cbf", - "shasum": "" - }, - "require": { - "php": ">=7.1.3", - "psr/log": "^1.0", - "symfony/console": "^4|^5" - }, - "require-dev": { - "g1a/composer-test-scenarios": "^3", - "php-coveralls/php-coveralls": "^2.2", - "phpunit/phpunit": "^6", - "squizlabs/php_codesniffer": "^3" - }, - "type": "library", - "extra": { - "scenarios": { - "symfony4": { - "require-dev": { - "symfony/console": "^4" - }, - "config": { - "platform": { - "php": "7.1.3" - } - } - } - }, - "branch-alias": { - "dev-master": "2.x-dev" - } - }, - "autoload": { - "psr-4": { - "Consolidation\\Log\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Greg Anderson", - "email": "greg.1.anderson@greenknowe.org" - } - ], - "description": "Improved Psr-3 / Psr\\Log logger based on Symfony Console components.", - "time": "2020-05-27T17:06:13+00:00" - }, { "name": "consolidation/output-formatters", "version": "4.1.1", @@ -4453,53 +4692,6 @@ ], "time": "2019-01-08T18:20:26+00:00" }, - { - "name": "psr/log", - "version": "1.1.3", - "source": { - "type": "git", - "url": "https://github.com/php-fig/log.git", - "reference": "0f73288fd15629204f9d42b7055f72dacbe811fc" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/0f73288fd15629204f9d42b7055f72dacbe811fc", - "reference": "0f73288fd15629204f9d42b7055f72dacbe811fc", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.1.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Log\\": "Psr/Log/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common interface for logging libraries", - "homepage": "https://github.com/php-fig/log", - "keywords": [ - "log", - "psr", - "psr-3" - ], - "time": "2020-03-23T09:12:05+00:00" - }, { "name": "sebastian/code-unit-reverse-lookup", "version": "1.0.1", @@ -5382,82 +5574,6 @@ "homepage": "https://symfony.com", "time": "2019-11-18T17:27:11+00:00" }, - { - "name": "symfony/console", - "version": "v5.0.8", - "source": { - "type": "git", - "url": "https://github.com/symfony/console.git", - "reference": "5fa1caadc8cdaa17bcfb25219f3b53fe294a9935" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/5fa1caadc8cdaa17bcfb25219f3b53fe294a9935", - "reference": "5fa1caadc8cdaa17bcfb25219f3b53fe294a9935", - "shasum": "" - }, - "require": { - "php": "^7.2.5", - "symfony/polyfill-mbstring": "~1.0", - "symfony/polyfill-php73": "^1.8", - "symfony/service-contracts": "^1.1|^2" - }, - "conflict": { - "symfony/dependency-injection": "<4.4", - "symfony/event-dispatcher": "<4.4", - "symfony/lock": "<4.4", - "symfony/process": "<4.4" - }, - "provide": { - "psr/log-implementation": "1.0" - }, - "require-dev": { - "psr/log": "~1.0", - "symfony/config": "^4.4|^5.0", - "symfony/dependency-injection": "^4.4|^5.0", - "symfony/event-dispatcher": "^4.4|^5.0", - "symfony/lock": "^4.4|^5.0", - "symfony/process": "^4.4|^5.0", - "symfony/var-dumper": "^4.4|^5.0" - }, - "suggest": { - "psr/log": "For using the console logger", - "symfony/event-dispatcher": "", - "symfony/lock": "", - "symfony/process": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "5.0-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Console\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony Console Component", - "homepage": "https://symfony.com", - "time": "2020-03-30T11:42:42+00:00" - }, { "name": "symfony/dependency-injection", "version": "v5.0.0", @@ -6010,64 +6126,6 @@ ], "time": "2019-11-18T17:27:11+00:00" }, - { - "name": "symfony/polyfill-php73", - "version": "v1.17.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-php73.git", - "reference": "a760d8964ff79ab9bf057613a5808284ec852ccc" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/a760d8964ff79ab9bf057613a5808284ec852ccc", - "reference": "a760d8964ff79ab9bf057613a5808284ec852ccc", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.17-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Php73\\": "" - }, - "files": [ - "bootstrap.php" - ], - "classmap": [ - "Resources/stubs" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "polyfill", - "portable", - "shim" - ], - "time": "2020-05-12T16:47:27+00:00" - }, { "name": "symfony/polyfill-php80", "version": "v1.17.1", @@ -6134,64 +6192,6 @@ ], "time": "2020-06-06T08:46:27+00:00" }, - { - "name": "symfony/service-contracts", - "version": "v2.0.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/service-contracts.git", - "reference": "144c5e51266b281231e947b51223ba14acf1a749" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/service-contracts/zipball/144c5e51266b281231e947b51223ba14acf1a749", - "reference": "144c5e51266b281231e947b51223ba14acf1a749", - "shasum": "" - }, - "require": { - "php": "^7.2.5", - "psr/container": "^1.0" - }, - "suggest": { - "symfony/service-implementation": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Contracts\\Service\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Generic abstractions related to writing services", - "homepage": "https://symfony.com", - "keywords": [ - "abstractions", - "contracts", - "decoupling", - "interfaces", - "interoperability", - "standards" - ], - "time": "2019-11-18T17:27:11+00:00" - }, { "name": "symfony/var-dumper", "version": "v5.0.8", @@ -6358,7 +6358,9 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "rudloff/alltube-library": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { diff --git a/index.php b/index.php index 4760670..ecbdea5 100644 --- a/index.php +++ b/index.php @@ -8,6 +8,7 @@ use Alltube\Controller\FrontController; use Alltube\Controller\JsonController; use Alltube\LocaleManager; use Alltube\LocaleMiddleware; +use Alltube\LoggerFactory; use Alltube\UglyRouter; use Alltube\ViewFactory; use Slim\App; @@ -61,6 +62,9 @@ try { die('Could not load Smarty: ' . $e->getMessage()); } +// Logger. +$container['logger'] = LoggerFactory::create(); + // Controllers. $frontController = new FrontController($container); $jsonController = new JsonController($container); diff --git a/tests/ControllerTest.php b/tests/ControllerTest.php index abb3756..9b2fc1b 100644 --- a/tests/ControllerTest.php +++ b/tests/ControllerTest.php @@ -11,6 +11,7 @@ use Alltube\Controller\DownloadController; use Alltube\Controller\FrontController; use Alltube\Exception\ConfigException; use Alltube\LocaleManager; +use Alltube\LoggerFactory; use Alltube\ViewFactory; use Slim\Container; use Slim\Http\Environment; @@ -63,6 +64,7 @@ abstract class ControllerTest extends BaseTest $this->response = new Response(); $this->container['locale'] = LocaleManager::getInstance(); $this->container['view'] = ViewFactory::create($this->container, $this->request); + $this->container['logger'] = LoggerFactory::create(); $frontController = new FrontController($this->container); $downloadController = new DownloadController($this->container);