From d414e67d3102ffd63db51d0c96f27e4636659b6f Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Mon, 1 Aug 2016 13:29:13 +0200 Subject: [PATCH] Cleanup doc --- classes/Config.php | 69 ++++++++++++++++++++++++--------- classes/VideoDownload.php | 52 +++++++++++++++---------- controllers/FrontController.php | 51 ++++++++++++++---------- tests/ConfigTest.php | 20 +--------- tests/VideoDownloadTest.php | 42 ++++++++++---------- 5 files changed, 136 insertions(+), 98 deletions(-) diff --git a/classes/Config.php b/classes/Config.php index 96e5ca5..c86f418 100644 --- a/classes/Config.php +++ b/classes/Config.php @@ -1,41 +1,68 @@ - * @license GNU General Public License http://www.gnu.org/licenses/gpl.html - * @link http://rudloff.pro - * */ + */ namespace Alltube; use Symfony\Component\Yaml\Yaml; /** - * Class to manage config parameters - * - * PHP Version 5.3.10 - * - * @category Youtube-dl - * @package Youtubedl - * @author Pierre Rudloff - * @license GNU General Public License http://www.gnu.org/licenses/gpl.html - * @link http://rudloff.pro - * */ + * Manage config parameters + */ class Config { + /** + * Singleton instance + * @var Config + */ private static $instance; + /** + * youtube-dl binary path + * @var string + */ public $youtubedl = 'vendor/rg3/youtube-dl/youtube_dl/__main__.py'; + + /** + * python binary path + * @var string + */ public $python = '/usr/bin/python'; + + /** + * youtube-dl parameters + * @var array + */ public $params = array('--no-playlist', '--no-warnings', '-f best[protocol^=http]', '--playlist-end', 1); + + /** + * Enable audio conversion + * @var bool + */ public $convert = false; + + /** + * avconv or ffmpeg binary path + * @var string + */ public $avconv = 'vendor/bin/ffmpeg'; + + /** + * rtmpdump binary path + * @var string + */ public $rtmpdump = 'vendor/bin/rtmpdump'; + + /** + * curl binary path + * @var string + */ public $curl = '/usr/bin/curl'; + + /** + * curl parameters + * @var array + */ public $curl_params = array(); /** @@ -72,6 +99,10 @@ class Config return self::$instance; } + /** + * Destroy singleton instance + * @return void + */ public static function destroyInstance() { self::$instance = null; diff --git a/classes/VideoDownload.php b/classes/VideoDownload.php index 5ed0dff..01b8ee2 100644 --- a/classes/VideoDownload.php +++ b/classes/VideoDownload.php @@ -1,15 +1,7 @@ - * @license GNU General Public License http://www.gnu.org/licenses/gpl.html - * @link http://rudloff.pro - * */ + */ namespace Alltube; use Symfony\Component\Process\Process; @@ -17,18 +9,14 @@ use Symfony\Component\Process\ProcessBuilder; use Chain\Chain; /** - * Main class - * - * PHP Version 5.3.10 - * - * @category Youtube-dl - * @package Youtubedl - * @author Pierre Rudloff - * @license GNU General Public License http://www.gnu.org/licenses/gpl.html - * @link http://rudloff.pro - * */ + * Extract info about videos + */ class VideoDownload { + + /** + * VideoDownload constructor + */ public function __construct() { $this->config = Config::getInstance(); @@ -44,7 +32,7 @@ class VideoDownload /** * List all extractors * - * @return array Extractors + * @return string[] Extractors * */ public function listExtractors() { @@ -114,6 +102,14 @@ class VideoDownload } } + /** + * Get filename of video file from URL of page + * + * @param string $url URL of page + * @param string $format Format to use for the video + * + * @return string Filename of extracted video + * */ public function getFilename($url, $format = null) { $this->procBuilder->setArguments( @@ -134,6 +130,14 @@ class VideoDownload } } + /** + * Get filename of audio from URL of page + * + * @param string $url URL of page + * @param string $format Format to use for the video + * + * @return string Filename of converted audio file + * */ public function getAudioFilename($url, $format = null) { return html_entity_decode( @@ -146,6 +150,14 @@ class VideoDownload ); } + /** + * Get audio stream of converted video + * + * @param string $url URL of page + * @param string $format Format to use for the video + * + * @return resource popen stream + */ public function getAudioStream($url, $format) { if (!shell_exec('which '.$this->config->avconv)) { diff --git a/controllers/FrontController.php b/controllers/FrontController.php index dbe0147..177e636 100644 --- a/controllers/FrontController.php +++ b/controllers/FrontController.php @@ -1,15 +1,7 @@ - * @license GNU General Public License http://www.gnu.org/licenses/gpl.html - * @link http://rudloff.pro - * */ + */ namespace Alltube\Controller; use Alltube\VideoDownload; @@ -21,21 +13,31 @@ use Slim\Container; /** * Main controller - * - * PHP Version 5.3.10 - * - * @category Youtube-dl - * @package Youtubedl - * @author Pierre Rudloff - * @license GNU General Public License http://www.gnu.org/licenses/gpl.html - * @link http://rudloff.pro - * */ + */ class FrontController { + /** + * Config instance + * @var Config + */ private $config; + + /** + * VideoDownload instance + * @var VideoDownload + */ private $download; + + /** + * Slim dependency container + * @var Container + */ private $container; + /** + * FrontController constructor + * @param Container $container Slim dependency container + */ public function __construct(Container $container) { $this->config = Config::getInstance(); @@ -93,7 +95,7 @@ class FrontController * @param Request $request PSR-7 request * @param Response $response PSR-7 response * - * @return void + * @return Response HTTP response */ public function video(Request $request, Response $response) { @@ -136,6 +138,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 + * @return Response HTTP response + */ public function error(Request $request, Response $response, \Exception $exception) { $this->container->view->render( @@ -156,7 +165,7 @@ class FrontController * @param Request $request PSR-7 request * @param Response $response PSR-7 response * - * @return void + * @return Response HTTP response */ public function redirect(Request $request, Response $response) { @@ -178,7 +187,7 @@ class FrontController * @param Request $request PSR-7 request * @param Response $response PSR-7 response * - * @return void + * @return Response HTTP response */ public function json(Request $request, Response $response) { diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index a103010..88acd67 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -1,30 +1,14 @@ - * @license GNU General Public License http://www.gnu.org/licenses/gpl.html - * @link http://rudloff.pro - * */ + */ namespace Alltube\Test; use Alltube\Config; /** * Unit tests for the Config class - * - * PHP Version 5.3.10 - * - * @category Youtube-dl - * @package Youtubedl - * @author Pierre Rudloff - * @license GNU General Public License http://www.gnu.org/licenses/gpl.html - * @link http://rudloff.pro - * */ + */ class ConfigTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/VideoDownloadTest.php b/tests/VideoDownloadTest.php index a64d382..4e642b3 100644 --- a/tests/VideoDownloadTest.php +++ b/tests/VideoDownloadTest.php @@ -1,37 +1,33 @@ - * @license GNU General Public License http://www.gnu.org/licenses/gpl.html - * @link http://rudloff.pro - * */ + */ namespace Alltube\Test; use Alltube\VideoDownload; /** * Unit tests for the VideoDownload class - * - * PHP Version 5.3.10 - * - * @category Youtube-dl - * @package Youtubedl - * @author Pierre Rudloff - * @license GNU General Public License http://www.gnu.org/licenses/gpl.html - * @link http://rudloff.pro - * */ + */ class VideoDownloadTest extends \PHPUnit_Framework_TestCase { + /** + * VideoDownload instance + * @var VideoDownload + */ + private $download; + + /** + * Initialize properties used by test + */ protected function setUp() { $this->download = new VideoDownload(); } + /** + * Destroy properties after test + */ protected function tearDown() { \Alltube\Config::destroyInstance(); @@ -53,6 +49,8 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase * * @param string $url URL * @param string $format Format + * @param string $filename Filename + * @param string $domain Domain * * @return void * @dataProvider urlProvider @@ -80,7 +78,7 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase /** * Provides URLs for tests * - * @return array + * @return array[] */ public function urlProvider() { @@ -123,7 +121,7 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase /** * Provides incorrect URLs for tests * - * @return array + * @return array[] */ public function errorUrlProvider() { @@ -171,6 +169,7 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase * * @param string $url URL * @param string $format Format + * @param string $filename Filename * * @return void * @dataProvider urlProvider @@ -200,6 +199,9 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase * * @param string $url URL * @param string $format Format + * @param string $filename Filename + * @param string $domain Domain + * @param string $audioFilename MP3 audio file name * * @return void * @dataProvider urlProvider