Cleanup doc

This commit is contained in:
Pierre Rudloff 2016-08-01 13:29:13 +02:00
parent 2a0fbb5032
commit d414e67d31
5 changed files with 136 additions and 98 deletions

View file

@ -1,41 +1,68 @@
<?php
/**
* Config class
*
* PHP Version 5.3.10
*
* @category Youtube-dl
* @package Youtubedl
* @author Pierre Rudloff <contact@rudloff.pro>
* @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 <contact@rudloff.pro>
* @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;

View file

@ -1,15 +1,7 @@
<?php
/**
* VideoDownload class
*
* PHP Version 5.3.10
*
* @category Youtube-dl
* @package Youtubedl
* @author Pierre Rudloff <contact@rudloff.pro>
* @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 <contact@rudloff.pro>
* @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)) {

View file

@ -1,15 +1,7 @@
<?php
/**
* FrontController class
*
* PHP Version 5.3.10
*
* @category Youtube-dl
* @package Youtubedl
* @author Pierre Rudloff <contact@rudloff.pro>
* @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 <contact@rudloff.pro>
* @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)
{

View file

@ -1,30 +1,14 @@
<?php
/**
* ConfigTest class
*
* PHP Version 5.3.10
*
* @category Youtube-dl
* @package Youtubedl
* @author Pierre Rudloff <contact@rudloff.pro>
* @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 <contact@rudloff.pro>
* @license GNU General Public License http://www.gnu.org/licenses/gpl.html
* @link http://rudloff.pro
* */
*/
class ConfigTest extends \PHPUnit_Framework_TestCase
{

View file

@ -1,37 +1,33 @@
<?php
/**
* VideoDownloadTest class
*
* PHP Version 5.3.10
*
* @category Youtube-dl
* @package Youtubedl
* @author Pierre Rudloff <contact@rudloff.pro>
* @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 <contact@rudloff.pro>
* @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