Cleanup doc
This commit is contained in:
parent
2a0fbb5032
commit
d414e67d31
5 changed files with 136 additions and 98 deletions
|
@ -1,41 +1,68 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Config class
|
* 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;
|
namespace Alltube;
|
||||||
|
|
||||||
use Symfony\Component\Yaml\Yaml;
|
use Symfony\Component\Yaml\Yaml;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to manage config parameters
|
* 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
|
|
||||||
* */
|
|
||||||
class Config
|
class Config
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Singleton instance
|
||||||
|
* @var Config
|
||||||
|
*/
|
||||||
private static $instance;
|
private static $instance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* youtube-dl binary path
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
public $youtubedl = 'vendor/rg3/youtube-dl/youtube_dl/__main__.py';
|
public $youtubedl = 'vendor/rg3/youtube-dl/youtube_dl/__main__.py';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* python binary path
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
public $python = '/usr/bin/python';
|
public $python = '/usr/bin/python';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* youtube-dl parameters
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
public $params = array('--no-playlist', '--no-warnings', '-f best[protocol^=http]', '--playlist-end', 1);
|
public $params = array('--no-playlist', '--no-warnings', '-f best[protocol^=http]', '--playlist-end', 1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable audio conversion
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
public $convert = false;
|
public $convert = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* avconv or ffmpeg binary path
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
public $avconv = 'vendor/bin/ffmpeg';
|
public $avconv = 'vendor/bin/ffmpeg';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* rtmpdump binary path
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
public $rtmpdump = 'vendor/bin/rtmpdump';
|
public $rtmpdump = 'vendor/bin/rtmpdump';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* curl binary path
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
public $curl = '/usr/bin/curl';
|
public $curl = '/usr/bin/curl';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* curl parameters
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
public $curl_params = array();
|
public $curl_params = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -72,6 +99,10 @@ class Config
|
||||||
return self::$instance;
|
return self::$instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroy singleton instance
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
public static function destroyInstance()
|
public static function destroyInstance()
|
||||||
{
|
{
|
||||||
self::$instance = null;
|
self::$instance = null;
|
||||||
|
|
|
@ -1,15 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* VideoDownload class
|
* 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;
|
namespace Alltube;
|
||||||
|
|
||||||
use Symfony\Component\Process\Process;
|
use Symfony\Component\Process\Process;
|
||||||
|
@ -17,18 +9,14 @@ use Symfony\Component\Process\ProcessBuilder;
|
||||||
use Chain\Chain;
|
use Chain\Chain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main class
|
* Extract info about videos
|
||||||
*
|
*/
|
||||||
* 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 VideoDownload
|
class VideoDownload
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VideoDownload constructor
|
||||||
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->config = Config::getInstance();
|
$this->config = Config::getInstance();
|
||||||
|
@ -44,7 +32,7 @@ class VideoDownload
|
||||||
/**
|
/**
|
||||||
* List all extractors
|
* List all extractors
|
||||||
*
|
*
|
||||||
* @return array Extractors
|
* @return string[] Extractors
|
||||||
* */
|
* */
|
||||||
public function listExtractors()
|
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)
|
public function getFilename($url, $format = null)
|
||||||
{
|
{
|
||||||
$this->procBuilder->setArguments(
|
$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)
|
public function getAudioFilename($url, $format = null)
|
||||||
{
|
{
|
||||||
return html_entity_decode(
|
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)
|
public function getAudioStream($url, $format)
|
||||||
{
|
{
|
||||||
if (!shell_exec('which '.$this->config->avconv)) {
|
if (!shell_exec('which '.$this->config->avconv)) {
|
||||||
|
|
|
@ -1,15 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* FrontController class
|
* 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;
|
namespace Alltube\Controller;
|
||||||
|
|
||||||
use Alltube\VideoDownload;
|
use Alltube\VideoDownload;
|
||||||
|
@ -21,21 +13,31 @@ use Slim\Container;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main controller
|
* 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
|
class FrontController
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Config instance
|
||||||
|
* @var Config
|
||||||
|
*/
|
||||||
private $config;
|
private $config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VideoDownload instance
|
||||||
|
* @var VideoDownload
|
||||||
|
*/
|
||||||
private $download;
|
private $download;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Slim dependency container
|
||||||
|
* @var Container
|
||||||
|
*/
|
||||||
private $container;
|
private $container;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FrontController constructor
|
||||||
|
* @param Container $container Slim dependency container
|
||||||
|
*/
|
||||||
public function __construct(Container $container)
|
public function __construct(Container $container)
|
||||||
{
|
{
|
||||||
$this->config = Config::getInstance();
|
$this->config = Config::getInstance();
|
||||||
|
@ -93,7 +95,7 @@ class FrontController
|
||||||
* @param Request $request PSR-7 request
|
* @param Request $request PSR-7 request
|
||||||
* @param Response $response PSR-7 response
|
* @param Response $response PSR-7 response
|
||||||
*
|
*
|
||||||
* @return void
|
* @return Response HTTP response
|
||||||
*/
|
*/
|
||||||
public function video(Request $request, Response $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)
|
public function error(Request $request, Response $response, \Exception $exception)
|
||||||
{
|
{
|
||||||
$this->container->view->render(
|
$this->container->view->render(
|
||||||
|
@ -156,7 +165,7 @@ class FrontController
|
||||||
* @param Request $request PSR-7 request
|
* @param Request $request PSR-7 request
|
||||||
* @param Response $response PSR-7 response
|
* @param Response $response PSR-7 response
|
||||||
*
|
*
|
||||||
* @return void
|
* @return Response HTTP response
|
||||||
*/
|
*/
|
||||||
public function redirect(Request $request, Response $response)
|
public function redirect(Request $request, Response $response)
|
||||||
{
|
{
|
||||||
|
@ -178,7 +187,7 @@ class FrontController
|
||||||
* @param Request $request PSR-7 request
|
* @param Request $request PSR-7 request
|
||||||
* @param Response $response PSR-7 response
|
* @param Response $response PSR-7 response
|
||||||
*
|
*
|
||||||
* @return void
|
* @return Response HTTP response
|
||||||
*/
|
*/
|
||||||
public function json(Request $request, Response $response)
|
public function json(Request $request, Response $response)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,30 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* ConfigTest class
|
* 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;
|
namespace Alltube\Test;
|
||||||
|
|
||||||
use Alltube\Config;
|
use Alltube\Config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for the Config class
|
* 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
|
class ConfigTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -1,37 +1,33 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* VideoDownloadTest class
|
* 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;
|
namespace Alltube\Test;
|
||||||
|
|
||||||
use Alltube\VideoDownload;
|
use Alltube\VideoDownload;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for the VideoDownload class
|
* 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
|
class VideoDownloadTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* VideoDownload instance
|
||||||
|
* @var VideoDownload
|
||||||
|
*/
|
||||||
|
private $download;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize properties used by test
|
||||||
|
*/
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
$this->download = new VideoDownload();
|
$this->download = new VideoDownload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroy properties after test
|
||||||
|
*/
|
||||||
protected function tearDown()
|
protected function tearDown()
|
||||||
{
|
{
|
||||||
\Alltube\Config::destroyInstance();
|
\Alltube\Config::destroyInstance();
|
||||||
|
@ -53,6 +49,8 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase
|
||||||
*
|
*
|
||||||
* @param string $url URL
|
* @param string $url URL
|
||||||
* @param string $format Format
|
* @param string $format Format
|
||||||
|
* @param string $filename Filename
|
||||||
|
* @param string $domain Domain
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
* @dataProvider urlProvider
|
* @dataProvider urlProvider
|
||||||
|
@ -80,7 +78,7 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase
|
||||||
/**
|
/**
|
||||||
* Provides URLs for tests
|
* Provides URLs for tests
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array[]
|
||||||
*/
|
*/
|
||||||
public function urlProvider()
|
public function urlProvider()
|
||||||
{
|
{
|
||||||
|
@ -123,7 +121,7 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase
|
||||||
/**
|
/**
|
||||||
* Provides incorrect URLs for tests
|
* Provides incorrect URLs for tests
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array[]
|
||||||
*/
|
*/
|
||||||
public function errorUrlProvider()
|
public function errorUrlProvider()
|
||||||
{
|
{
|
||||||
|
@ -171,6 +169,7 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase
|
||||||
*
|
*
|
||||||
* @param string $url URL
|
* @param string $url URL
|
||||||
* @param string $format Format
|
* @param string $format Format
|
||||||
|
* @param string $filename Filename
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
* @dataProvider urlProvider
|
* @dataProvider urlProvider
|
||||||
|
@ -200,6 +199,9 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase
|
||||||
*
|
*
|
||||||
* @param string $url URL
|
* @param string $url URL
|
||||||
* @param string $format Format
|
* @param string $format Format
|
||||||
|
* @param string $filename Filename
|
||||||
|
* @param string $domain Domain
|
||||||
|
* @param string $audioFilename MP3 audio file name
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
* @dataProvider urlProvider
|
* @dataProvider urlProvider
|
||||||
|
|
Loading…
Reference in a new issue