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

View file

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

View file

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