This commit is contained in:
Pierre Rudloff 2015-10-29 21:23:02 +01:00
parent 299634b023
commit e35314b492
2 changed files with 137 additions and 126 deletions

249
index.php
View File

@ -15,138 +15,149 @@
use Alltube\VideoDownload;
require_once 'common.php';
$app = new \Slim\Slim(array(
'view' => new \Slim\Views\Smarty()
));
$app = new \Slim\Slim(
array(
'view' => new \Slim\Views\Smarty()
)
);
$view = $app->view();
$view->parserExtensions = array(
dirname(__FILE__).'/vendor/slim/views/SmartyPlugins',
);
$app->get('/', function () {
global $app;
$app->render(
'head.tpl',
array(
'class'=>'index'
)
);
$app->render(
'header.tpl'
);
$app->render(
'index.tpl',
array(
'convert'=>CONVERT
)
);
$app->render('footer.tpl');
});
$app->get('/extractors', function () {
global $app;
$app->render(
'head.tpl',
array(
'class'=>'extractors'
)
);
$app->render('header.tpl');
$app->render('logo.tpl');
$app->render(
'extractors.tpl',
array(
'extractors'=>VideoDownload::listExtractors()
)
);
$app->render('footer.tpl');
})->name('extractors');
$app->get('/video', function () {
global $app;
if (isset($_GET["url"])) {
if (isset($_GET['audio'])) {
try {
$video = VideoDownload::getJSON($_GET["url"]);
//Vimeo needs a correct user-agent
$UA = VideoDownload::getUA();
ini_set(
'user_agent',
$UA
);
$url_info = parse_url($video->url);
if ($url_info['scheme'] == 'rtmp') {
header(
'Content-Disposition: attachment; filename="'.
html_entity_decode(
pathinfo(
VideoDownload::getFilename(
$video->webpage_url
), PATHINFO_FILENAME
).'.mp3', ENT_COMPAT, 'ISO-8859-1'
).'"'
);
header("Content-Type: audio/mpeg");
passthru(
'/usr/bin/rtmpdump -q -r '.escapeshellarg($video->url).
' | '.AVCONV.' -v quiet -i - -f mp3 -vn pipe:1'
);
exit;
} else {
header(
'Content-Disposition: attachment; filename="'.
html_entity_decode(
pathinfo(
VideoDownload::getFilename(
$video->webpage_url
), PATHINFO_FILENAME
).'.mp3', ENT_COMPAT, 'ISO-8859-1'
).'"'
);
header("Content-Type: audio/mpeg");
passthru(
'curl --user-agent '.escapeshellarg($UA).
' '.escapeshellarg($video->url).
' | '.AVCONV.' -v quiet -i - -f mp3 -vn pipe:1'
);
exit;
}
} catch (Exception $e) {
$error = $e->getMessage();
}
} else {
try {
$video = VideoDownload::getJSON($_GET["url"]);
$app->render(
'head.tpl',
array(
'class'=>'video'
)
);
$app->render(
'video.tpl',
array(
'video'=>$video
)
);
$app->render('footer.tpl');
} catch (Exception $e) {
$error = $e->getMessage();
}
}
}
if (isset($error)) {
$app->get(
'/',
function () {
global $app;
$app->render(
'head.tpl',
array(
'class'=>'video'
'class'=>'index'
)
);
$app->render(
'error.tpl',
'header.tpl'
);
$app->render(
'index.tpl',
array(
'errors'=>$error
'convert'=>CONVERT
)
);
$app->render('footer.tpl');
}
})->name('video');
);
$app->get(
'/extractors',
function () {
global $app;
$app->render(
'head.tpl',
array(
'class'=>'extractors'
)
);
$app->render('header.tpl');
$app->render('logo.tpl');
$app->render(
'extractors.tpl',
array(
'extractors'=>VideoDownload::listExtractors()
)
);
$app->render('footer.tpl');
}
)->name('extractors');
$app->get(
'/video',
function () {
global $app;
if (isset($_GET["url"])) {
if (isset($_GET['audio'])) {
try {
$video = VideoDownload::getJSON($_GET["url"]);
//Vimeo needs a correct user-agent
$UA = VideoDownload::getUA();
ini_set(
'user_agent',
$UA
);
$url_info = parse_url($video->url);
if ($url_info['scheme'] == 'rtmp') {
header(
'Content-Disposition: attachment; filename="'.
html_entity_decode(
pathinfo(
VideoDownload::getFilename(
$video->webpage_url
), PATHINFO_FILENAME
).'.mp3', ENT_COMPAT, 'ISO-8859-1'
).'"'
);
header("Content-Type: audio/mpeg");
passthru(
'/usr/bin/rtmpdump -q -r '.escapeshellarg($video->url).
' | '.AVCONV.' -v quiet -i - -f mp3 -vn pipe:1'
);
exit;
} else {
header(
'Content-Disposition: attachment; filename="'.
html_entity_decode(
pathinfo(
VideoDownload::getFilename(
$video->webpage_url
), PATHINFO_FILENAME
).'.mp3', ENT_COMPAT, 'ISO-8859-1'
).'"'
);
header("Content-Type: audio/mpeg");
passthru(
'curl --user-agent '.escapeshellarg($UA).
' '.escapeshellarg($video->url).
' | '.AVCONV.' -v quiet -i - -f mp3 -vn pipe:1'
);
exit;
}
} catch (Exception $e) {
$error = $e->getMessage();
}
} else {
try {
$video = VideoDownload::getJSON($_GET["url"]);
$app->render(
'head.tpl',
array(
'class'=>'video'
)
);
$app->render(
'video.tpl',
array(
'video'=>$video
)
);
$app->render('footer.tpl');
} catch (Exception $e) {
$error = $e->getMessage();
}
}
}
if (isset($error)) {
$app->render(
'head.tpl',
array(
'class'=>'video'
)
);
$app->render(
'error.tpl',
array(
'errors'=>$error
)
);
$app->render('footer.tpl');
}
}
)->name('video');
$app->run();

View File

@ -53,7 +53,7 @@ class VideoDownloadTest extends PHPUnit_Framework_TestCase
* @param string $url URL
* @param string $format Format
*
* @return void
* @return void
* @dataProvider urlProvider
*/
public function testGetURL($url, $format)
@ -68,9 +68,9 @@ class VideoDownloadTest extends PHPUnit_Framework_TestCase
*
* @param string $url URL
*
* @return void
* @return void
* @expectedException Exception
* @dataProvider ErrorUrlProvider
* @dataProvider ErrorUrlProvider
*/
public function testGetURLError($url)
{
@ -120,7 +120,7 @@ class VideoDownloadTest extends PHPUnit_Framework_TestCase
* @param string $format Format
* @param string $result Expected filename
*
* @return void
* @return void
* @dataProvider URLProvider
*/
public function testGetFilename($url, $format, $result)
@ -135,7 +135,7 @@ class VideoDownloadTest extends PHPUnit_Framework_TestCase
* @param string $url URL
* @param string $format Format
*
* @return void
* @return void
* @dataProvider URLProvider
*/
public function testGetJSON($url, $format)
@ -154,9 +154,9 @@ class VideoDownloadTest extends PHPUnit_Framework_TestCase
*
* @param string $url URL
*
* @return void
* @return void
* @expectedException Exception
* @dataProvider ErrorURLProvider
* @dataProvider ErrorURLProvider
*/
public function testGetJSONError($url)
{