From 9ffd1d276940b1bff2af120bb544c5de871733b4 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Thu, 29 Oct 2015 22:32:36 +0100 Subject: [PATCH] Controllers --- composer.json | 3 +- composer.lock | 2 +- controllers/FrontController.php | 135 ++++++++++++++++++++++++++++++++ index.php | 130 +----------------------------- 4 files changed, 141 insertions(+), 129 deletions(-) create mode 100644 controllers/FrontController.php diff --git a/composer.json b/composer.json index 8759dcd..5854bad 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,8 @@ ], "autoload": { "psr-4": { - "Alltube\\": "classes/" + "Alltube\\": "classes/", + "Alltube\\Controller\\": "controllers/" } } } diff --git a/composer.lock b/composer.lock index b4b3c99..5484fec 100644 --- a/composer.lock +++ b/composer.lock @@ -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": [ { diff --git a/controllers/FrontController.php b/controllers/FrontController.php new file mode 100644 index 0000000..d17fe24 --- /dev/null +++ b/controllers/FrontController.php @@ -0,0 +1,135 @@ +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'); + } + } +} diff --git a/index.php b/index.php index cc71393..0d94974 100644 --- a/index.php +++ b/index.php @@ -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();