Controllers

This commit is contained in:
Pierre Rudloff 2015-10-29 22:32:36 +01:00
parent e8d7ef5d01
commit 9ffd1d2769
4 changed files with 141 additions and 129 deletions

View File

@ -44,7 +44,8 @@
],
"autoload": {
"psr-4": {
"Alltube\\": "classes/"
"Alltube\\": "classes/",
"Alltube\\Controller\\": "controllers/"
}
}
}

2
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "e2f86695cdc0cea75a4d55c83a8e5845",
"hash": "a3bd183ffb07dc7dd09cf58f9b44f849",
"content-hash": "171a72e54b647ef8b67a785971c887fa",
"packages": [
{

View File

@ -0,0 +1,135 @@
<?php
namespace Alltube\Controller;
use Alltube\VideoDownload;
class FrontController {
static function index() {
global $app;
$app->render(
'head.tpl',
array(
'class'=>'index'
)
);
$app->render(
'header.tpl'
);
$app->render(
'index.tpl',
array(
'convert'=>CONVERT
)
);
$app->render('footer.tpl');
}
static function extractors() {
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');
}
static function video() {
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');
}
}
}

130
index.php
View File

@ -26,138 +26,14 @@ $view->parserExtensions = array(
);
$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');
}
array('Alltube\Controller\FrontController', 'index')
);
$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');
}
array('Alltube\Controller\FrontController', 'extractors')
)->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');
}
}
array('Alltube\Controller\FrontController', 'video')
)->name('video');
$app->run();