This commit is contained in:
Pierre Rudloff 2015-10-31 15:50:32 +01:00
parent 5249df52e6
commit 0974bf360c
3 changed files with 75 additions and 11 deletions

View file

@ -33,7 +33,11 @@ Class Config
public $convert = false; public $convert = false;
public $avconv = __DIR__.'/ffmpeg/ffmpeg'; public $avconv = __DIR__.'/ffmpeg/ffmpeg';
private function __construct() { /**
* Config constructor
*/
private function __construct()
{
$yaml = Yaml::parse(__DIR__.'/../config.yml'); $yaml = Yaml::parse(__DIR__.'/../config.yml');
foreach ($yaml as $param=>$value) { foreach ($yaml as $param=>$value) {
if (isset($this->$param)) { if (isset($this->$param)) {
@ -45,8 +49,13 @@ Class Config
} }
} }
public static function getInstance() { /**
if(is_null(self::$_instance)) { * Get singleton instance
* @return Config
*/
public static function getInstance()
{
if (is_null(self::$_instance)) {
self::$_instance = new Config(); self::$_instance = new Config();
} }
return self::$_instance; return self::$_instance;

View file

@ -1,10 +1,38 @@
<?php <?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; namespace Alltube\Controller;
use Alltube\VideoDownload; use Alltube\VideoDownload;
use Alltube\Config; use Alltube\Config;
/**
* 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 { /**
static function index() { * Display index page
* @return void
*/
static function index()
{
global $app; global $app;
$config = Config::getInstance(); $config = Config::getInstance();
$app->render( $app->render(
@ -25,7 +53,12 @@ class FrontController {
$app->render('footer.tpl'); $app->render('footer.tpl');
} }
static function extractors() { /**
* Display a list of extractors
* @return void
*/
static function extractors()
{
global $app; global $app;
$app->render( $app->render(
'head.tpl', 'head.tpl',
@ -44,7 +77,12 @@ class FrontController {
$app->render('footer.tpl'); $app->render('footer.tpl');
} }
static function video() { /**
* Dislay information about the video
* @return void
*/
static function video()
{
global $app; global $app;
$config = Config::getInstance(); $config = Config::getInstance();
if (isset($_GET["url"])) { if (isset($_GET["url"])) {
@ -74,7 +112,8 @@ class FrontController {
header("Content-Type: audio/mpeg"); header("Content-Type: audio/mpeg");
passthru( passthru(
'/usr/bin/rtmpdump -q -r '.escapeshellarg($video->url). '/usr/bin/rtmpdump -q -r '.escapeshellarg($video->url).
' | '.$config->avconv.' -v quiet -i - -f mp3 -vn pipe:1' ' | '.$config->avconv.
' -v quiet -i - -f mp3 -vn pipe:1'
); );
exit; exit;
} else { } else {
@ -93,7 +132,8 @@ class FrontController {
passthru( passthru(
'curl --user-agent '.escapeshellarg($UA). 'curl --user-agent '.escapeshellarg($UA).
' '.escapeshellarg($video->url). ' '.escapeshellarg($video->url).
' | '.$config->avconv.' -v quiet -i - -f mp3 -vn pipe:1' ' | '.$config->avconv.
' -v quiet -i - -f mp3 -vn pipe:1'
); );
exit; exit;
} }
@ -138,7 +178,12 @@ class FrontController {
} }
} }
static function redirect() { /**
* Redirect to video file
* @return void
*/
static function redirect()
{
global $app; global $app;
if (isset($_GET["url"])) { if (isset($_GET["url"])) {
try { try {
@ -151,7 +196,12 @@ class FrontController {
} }
} }
static function json() { /**
* Output JSON info about the video
* @return void
*/
static function json()
{
global $app; global $app;
if (isset($_GET["url"])) { if (isset($_GET["url"])) {
$app->response->headers->set('Content-Type', 'application/json'); $app->response->headers->set('Content-Type', 'application/json');

View file

@ -25,6 +25,11 @@ use Alltube\Config;
* */ * */
class ConfigTest extends PHPUnit_Framework_TestCase class ConfigTest extends PHPUnit_Framework_TestCase
{ {
/**
* Test the getInstance function
* @return void
*/
public function testGetInstance() public function testGetInstance()
{ {
putenv('CONVERT=1'); putenv('CONVERT=1');