YAML config file
This commit is contained in:
parent
8d4cf18360
commit
5249df52e6
15 changed files with 168 additions and 67 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -9,3 +9,4 @@ ffmpeg-*/
|
||||||
alltube-release.zip
|
alltube-release.zip
|
||||||
coverage/
|
coverage/
|
||||||
bower_components/
|
bower_components/
|
||||||
|
config.yml
|
||||||
|
|
|
@ -29,7 +29,7 @@ module.exports = function (grunt) {
|
||||||
},
|
},
|
||||||
phpcs: {
|
phpcs: {
|
||||||
php: {
|
php: {
|
||||||
src: ['*.php']
|
src: ['*.php', 'classes/*.php', 'controllers/*.php']
|
||||||
},
|
},
|
||||||
tests: {
|
tests: {
|
||||||
src: ['tests/*.php']
|
src: ['tests/*.php']
|
||||||
|
@ -51,7 +51,7 @@ module.exports = function (grunt) {
|
||||||
options: {
|
options: {
|
||||||
archive: 'alltube-release.zip'
|
archive: 'alltube-release.zip'
|
||||||
},
|
},
|
||||||
src: ['*.php', '!config.php', 'dist/**', 'fonts/**', '.htaccess', 'img/**', 'js/**', 'LICENSE', 'README.md', 'robots.txt', 'sitemap.xml', 'templates/**', 'templates_c/', 'vendor/**', 'classes/**', 'controllers/**', 'bower_components/**']
|
src: ['*.php', '!config.yml', 'dist/**', 'fonts/**', '.htaccess', 'img/**', 'js/**', 'LICENSE', 'README.md', 'robots.txt', 'sitemap.xml', 'templates/**', 'templates_c/', 'vendor/**', 'classes/**', 'controllers/**', 'bower_components/**']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ You should also ensure that the *templates_c* folder has the right permissions:
|
||||||
|
|
||||||
If you want to use a custom config, you need to create a config file:
|
If you want to use a custom config, you need to create a config file:
|
||||||
|
|
||||||
cp config.example.php config.php
|
cp config.example.yml config.yml
|
||||||
|
|
||||||
|
|
||||||
##License
|
##License
|
||||||
|
@ -33,7 +33,7 @@ __Please use a different name and logo if you run it on a public server.__
|
||||||
|
|
||||||
##Other dependencies
|
##Other dependencies
|
||||||
You need [avconv](https://libav.org/avconv.html) and [rtmpdump](http://rtmpdump.mplayerhq.hu/) in order to enable conversions.
|
You need [avconv](https://libav.org/avconv.html) and [rtmpdump](http://rtmpdump.mplayerhq.hu/) in order to enable conversions.
|
||||||
If you don't want to enable conversions, you can disable it in *config.php*.
|
If you don't want to enable conversions, you can disable it in *config.yml*.
|
||||||
|
|
||||||
On Debian-based systems:
|
On Debian-based systems:
|
||||||
|
|
||||||
|
|
54
classes/Config.php
Normal file
54
classes/Config.php
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
<?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
|
||||||
|
* */
|
||||||
|
Class Config
|
||||||
|
{
|
||||||
|
private static $_instance;
|
||||||
|
|
||||||
|
public $youtubedl = __DIR__.'/../vendor/rg3/youtube-dl/youtube_dl/__main__.py';
|
||||||
|
public $python = '/usr/bin/python';
|
||||||
|
public $params = '--no-playlist --no-warnings -f best';
|
||||||
|
public $convert = false;
|
||||||
|
public $avconv = __DIR__.'/ffmpeg/ffmpeg';
|
||||||
|
|
||||||
|
private function __construct() {
|
||||||
|
$yaml = Yaml::parse(__DIR__.'/../config.yml');
|
||||||
|
foreach ($yaml as $param=>$value) {
|
||||||
|
if (isset($this->$param)) {
|
||||||
|
$this->$param = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (getenv('CONVERT')) {
|
||||||
|
$this->convert = getenv('CONVERT');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getInstance() {
|
||||||
|
if(is_null(self::$_instance)) {
|
||||||
|
self::$_instance = new Config();
|
||||||
|
}
|
||||||
|
return self::$_instance;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* PHP web interface for youtube-dl (http://rg3.github.com/youtube-dl/)
|
* VideoDownload class
|
||||||
* Main class
|
|
||||||
*
|
*
|
||||||
* PHP Version 5.3.10
|
* PHP Version 5.3.10
|
||||||
*
|
*
|
||||||
|
@ -13,7 +12,6 @@
|
||||||
* */
|
* */
|
||||||
namespace Alltube;
|
namespace Alltube;
|
||||||
/**
|
/**
|
||||||
* PHP web interface for youtube-dl (http://rg3.github.com/youtube-dl/)
|
|
||||||
* Main class
|
* Main class
|
||||||
*
|
*
|
||||||
* PHP Version 5.3.10
|
* PHP Version 5.3.10
|
||||||
|
@ -33,8 +31,9 @@ Class VideoDownload
|
||||||
* */
|
* */
|
||||||
static function getUA()
|
static function getUA()
|
||||||
{
|
{
|
||||||
|
$config = Config::getInstance();
|
||||||
exec(
|
exec(
|
||||||
PYTHON.' '.YOUTUBE_DL.' --dump-user-agent',
|
$config->python.' '.$config->youtubedl.' --dump-user-agent',
|
||||||
$version
|
$version
|
||||||
);
|
);
|
||||||
return $version[0];
|
return $version[0];
|
||||||
|
@ -47,8 +46,9 @@ Class VideoDownload
|
||||||
* */
|
* */
|
||||||
static function listExtractors()
|
static function listExtractors()
|
||||||
{
|
{
|
||||||
|
$config = Config::getInstance();
|
||||||
exec(
|
exec(
|
||||||
PYTHON.' '.YOUTUBE_DL.' --list-extractors',
|
$config->python.' '.$config->youtubedl.' --list-extractors',
|
||||||
$extractors
|
$extractors
|
||||||
);
|
);
|
||||||
return $extractors;
|
return $extractors;
|
||||||
|
@ -64,7 +64,8 @@ Class VideoDownload
|
||||||
* */
|
* */
|
||||||
static function getFilename($url, $format=null)
|
static function getFilename($url, $format=null)
|
||||||
{
|
{
|
||||||
$cmd=PYTHON.' '.YOUTUBE_DL;
|
$config = Config::getInstance();
|
||||||
|
$cmd=$config->python.' '.$config->youtubedl;
|
||||||
if (isset($format)) {
|
if (isset($format)) {
|
||||||
$cmd .= ' -f '.escapeshellarg($format);
|
$cmd .= ' -f '.escapeshellarg($format);
|
||||||
}
|
}
|
||||||
|
@ -86,7 +87,8 @@ Class VideoDownload
|
||||||
* */
|
* */
|
||||||
static function getJSON($url, $format=null)
|
static function getJSON($url, $format=null)
|
||||||
{
|
{
|
||||||
$cmd=PYTHON.' '.YOUTUBE_DL.' '.PARAMS;
|
$config = Config::getInstance();
|
||||||
|
$cmd=$config->python.' '.$config->youtubedl.' '.$config->params;
|
||||||
if (isset($format)) {
|
if (isset($format)) {
|
||||||
$cmd .= ' -f '.escapeshellarg($format);
|
$cmd .= ' -f '.escapeshellarg($format);
|
||||||
}
|
}
|
||||||
|
@ -111,7 +113,8 @@ Class VideoDownload
|
||||||
* */
|
* */
|
||||||
static function getURL($url, $format=null)
|
static function getURL($url, $format=null)
|
||||||
{
|
{
|
||||||
$cmd=PYTHON.' '.YOUTUBE_DL.' '.PARAMS;
|
$config = Config::getInstance();
|
||||||
|
$cmd=$config->python.' '.$config->youtubedl.' '.$config->params;
|
||||||
if (isset($format)) {
|
if (isset($format)) {
|
||||||
$cmd .= ' -f '.escapeshellarg($format);
|
$cmd .= ' -f '.escapeshellarg($format);
|
||||||
}
|
}
|
||||||
|
|
21
common.php
21
common.php
|
@ -1,21 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* PHP web interface for youtube-dl (http://rg3.github.com/youtube-dl/)
|
|
||||||
* PHP file included on all pages
|
|
||||||
*
|
|
||||||
* PHP Version 5.3.10
|
|
||||||
*
|
|
||||||
* @category Youtube-dl
|
|
||||||
* @package Youtubedl
|
|
||||||
* @author Pierre Rudloff <contact@rudloff.pro>
|
|
||||||
* @author Olivier Haquette <contact@olivierhaquette.fr>
|
|
||||||
* @license GNU General Public License http://www.gnu.org/licenses/gpl.html
|
|
||||||
* @link http://rudloff.pro
|
|
||||||
* */
|
|
||||||
require_once __DIR__.'/vendor/autoload.php';
|
|
||||||
if (is_file('config.php')) {
|
|
||||||
include_once 'config.php';
|
|
||||||
} else {
|
|
||||||
include_once 'config.example.php';
|
|
||||||
}
|
|
||||||
define('FILENAME', basename($_SERVER["SCRIPT_FILENAME"]));
|
|
|
@ -9,7 +9,8 @@
|
||||||
"rg3/youtube-dl": "2015.10.24",
|
"rg3/youtube-dl": "2015.10.24",
|
||||||
"slim/slim": "~2.6.2",
|
"slim/slim": "~2.6.2",
|
||||||
"slim/views": "~0.1.3",
|
"slim/views": "~0.1.3",
|
||||||
"rudloff/smarty-plugin-noscheme": "~0.1.0"
|
"rudloff/smarty-plugin-noscheme": "~0.1.0",
|
||||||
|
"symfony/yaml": "~2.7.6"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"symfony/var-dumper": "~2.7.6"
|
"symfony/var-dumper": "~2.7.6"
|
||||||
|
|
50
composer.lock
generated
50
composer.lock
generated
|
@ -4,8 +4,8 @@
|
||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"hash": "82f7ed8800ea2323a9c82063c52a5aec",
|
"hash": "a7e5944a818030d017d39d13b9ec0ffd",
|
||||||
"content-hash": "d0cc534e5934271396a1b66d8d0ff51b",
|
"content-hash": "2d61af9410d3e5f69fa0d6a956210a83",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "jeremykendall/php-domain-parser",
|
"name": "jeremykendall/php-domain-parser",
|
||||||
|
@ -380,6 +380,52 @@
|
||||||
"templating"
|
"templating"
|
||||||
],
|
],
|
||||||
"time": "2015-06-18 00:55:59"
|
"time": "2015-06-18 00:55:59"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "symfony/yaml",
|
||||||
|
"version": "v2.7.6",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/symfony/yaml.git",
|
||||||
|
"reference": "eca9019c88fbe250164affd107bc8057771f3f4d"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/symfony/yaml/zipball/eca9019c88fbe250164affd107bc8057771f3f4d",
|
||||||
|
"reference": "eca9019c88fbe250164affd107bc8057771f3f4d",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=5.3.9"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "2.7-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Symfony\\Component\\Yaml\\": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Fabien Potencier",
|
||||||
|
"email": "fabien@symfony.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Symfony Community",
|
||||||
|
"homepage": "https://symfony.com/contributors"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Symfony Yaml Component",
|
||||||
|
"homepage": "https://symfony.com",
|
||||||
|
"time": "2015-10-11 09:39:48"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"packages-dev": [
|
"packages-dev": [
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* PHP web interface for youtube-dl (http://rg3.github.com/youtube-dl/)
|
|
||||||
* Config file
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* */
|
|
||||||
define('YOUTUBE_DL', __DIR__.'/vendor/rg3/youtube-dl/youtube_dl/__main__.py');
|
|
||||||
define('PYTHON', '/usr/bin/python');
|
|
||||||
define('PARAMS', '--no-playlist --no-warnings -f best');
|
|
||||||
if (getenv('CONVERT')) {
|
|
||||||
define('CONVERT', getenv('CONVERT'));
|
|
||||||
} else {
|
|
||||||
define('CONVERT', false);
|
|
||||||
}
|
|
||||||
define('AVCONV', __DIR__.'/ffmpeg/ffmpeg');
|
|
||||||
define('MAINTENANCE', false);
|
|
||||||
define('DISABLED', false);
|
|
5
config.example.yml
Normal file
5
config.example.yml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
youtubedl: vendor/rg3/youtube-dl/youtube_dl/__main__.py
|
||||||
|
python: /usr/bin/python
|
||||||
|
params: --no-playlist --no-warnings -f best
|
||||||
|
convert: false
|
||||||
|
avconv: ffmpeg/ffmpeg
|
|
@ -1,10 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Alltube\Controller;
|
namespace Alltube\Controller;
|
||||||
use Alltube\VideoDownload;
|
use Alltube\VideoDownload;
|
||||||
|
use Alltube\Config;
|
||||||
|
|
||||||
class FrontController {
|
class FrontController {
|
||||||
static function index() {
|
static function index() {
|
||||||
global $app;
|
global $app;
|
||||||
|
$config = Config::getInstance();
|
||||||
$app->render(
|
$app->render(
|
||||||
'head.tpl',
|
'head.tpl',
|
||||||
array(
|
array(
|
||||||
|
@ -17,7 +19,7 @@ class FrontController {
|
||||||
$app->render(
|
$app->render(
|
||||||
'index.tpl',
|
'index.tpl',
|
||||||
array(
|
array(
|
||||||
'convert'=>CONVERT
|
'convert'=>$config->convert
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$app->render('footer.tpl');
|
$app->render('footer.tpl');
|
||||||
|
@ -44,6 +46,7 @@ class FrontController {
|
||||||
|
|
||||||
static function video() {
|
static function video() {
|
||||||
global $app;
|
global $app;
|
||||||
|
$config = Config::getInstance();
|
||||||
if (isset($_GET["url"])) {
|
if (isset($_GET["url"])) {
|
||||||
if (isset($_GET['audio'])) {
|
if (isset($_GET['audio'])) {
|
||||||
try {
|
try {
|
||||||
|
@ -71,7 +74,7 @@ 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).
|
||||||
' | '.AVCONV.' -v quiet -i - -f mp3 -vn pipe:1'
|
' | '.$config->avconv.' -v quiet -i - -f mp3 -vn pipe:1'
|
||||||
);
|
);
|
||||||
exit;
|
exit;
|
||||||
} else {
|
} else {
|
||||||
|
@ -90,7 +93,7 @@ class FrontController {
|
||||||
passthru(
|
passthru(
|
||||||
'curl --user-agent '.escapeshellarg($UA).
|
'curl --user-agent '.escapeshellarg($UA).
|
||||||
' '.escapeshellarg($video->url).
|
' '.escapeshellarg($video->url).
|
||||||
' | '.AVCONV.' -v quiet -i - -f mp3 -vn pipe:1'
|
' | '.$config->avconv.' -v quiet -i - -f mp3 -vn pipe:1'
|
||||||
);
|
);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
* @license GNU General Public License http://www.gnu.org/licenses/gpl.html
|
* @license GNU General Public License http://www.gnu.org/licenses/gpl.html
|
||||||
* @link http://rudloff.pro
|
* @link http://rudloff.pro
|
||||||
* */
|
* */
|
||||||
|
require_once __DIR__.'/vendor/autoload.php';
|
||||||
use Alltube\VideoDownload;
|
use Alltube\VideoDownload;
|
||||||
require_once 'common.php';
|
|
||||||
|
|
||||||
$app = new \Slim\Slim(
|
$app = new \Slim\Slim(
|
||||||
array(
|
array(
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<phpunit>
|
<phpunit bootstrap="vendor/autoload.php">
|
||||||
<filter>
|
<filter>
|
||||||
<whitelist>
|
<whitelist>
|
||||||
<file>download.php</file>
|
<directory>classes/</directory>
|
||||||
</whitelist>
|
</whitelist>
|
||||||
</filter>
|
</filter>
|
||||||
<testsuites>
|
<testsuites>
|
||||||
|
|
34
tests/ConfigTest.php
Normal file
34
tests/ConfigTest.php
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
<?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
|
||||||
|
* */
|
||||||
|
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
|
||||||
|
{
|
||||||
|
public function testGetInstance()
|
||||||
|
{
|
||||||
|
putenv('CONVERT=1');
|
||||||
|
$config = Config::getInstance();
|
||||||
|
$this->assertEquals($config->convert, true);
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,7 +11,6 @@
|
||||||
* @link http://rudloff.pro
|
* @link http://rudloff.pro
|
||||||
* */
|
* */
|
||||||
use Alltube\VideoDownload;
|
use Alltube\VideoDownload;
|
||||||
require_once __DIR__.'/../common.php';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for the VideoDownload class
|
* Unit tests for the VideoDownload class
|
||||||
|
|
Loading…
Reference in a new issue