From 299634b023c0a96ca897b8cb0c5994331643868d Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Thu, 29 Oct 2015 21:19:40 +0100 Subject: [PATCH] Use Slim framework (fixes #33) --- .htaccess | 3 + common.php | 12 ---- composer.json | 4 +- composer.lock | 103 +++++++++++++++++++++++++++++- config.example.php | 1 - disabled.php | 22 ------- extractors.php | 23 ------- index.php | 146 ++++++++++++++++++++++++++++++++++++++++--- maintenance.php | 22 ------- templates/head.tpl | 6 +- templates/header.tpl | 4 +- templates/index.tpl | 6 +- templates/logo.tpl | 2 +- youtoubeur.php | 14 ----- 14 files changed, 255 insertions(+), 113 deletions(-) delete mode 100644 disabled.php delete mode 100644 extractors.php delete mode 100644 maintenance.php delete mode 100644 youtoubeur.php diff --git a/.htaccess b/.htaccess index d7f9cb7..5591820 100644 --- a/.htaccess +++ b/.htaccess @@ -8,3 +8,6 @@ AddType application/x-web-app-manifest+json .webapp ExpiresByType image/svg+xml "access plus 1 week" FileETag None +RewriteEngine On +RewriteCond %{REQUEST_FILENAME} !-f +RewriteRule ^ index.php [QSA,L] diff --git a/common.php b/common.php index 4db3064..ad61333 100644 --- a/common.php +++ b/common.php @@ -19,15 +19,3 @@ if (is_file('config.php')) { include_once 'config.example.php'; } define('FILENAME', basename($_SERVER["SCRIPT_FILENAME"])); -if (DISABLED && FILENAME != 'disabled.php') { - header('Location: disabled.php'); exit; -} else if (MAINTENANCE && FILENAME != 'maintenance.php') { - header('Location: maintenance.php'); exit; -} -$smarty = new Smarty(); -$smarty->assign( - array( - 'base_url'=>BASE_URL, - 'convert'=>CONVERT - ) -); diff --git a/composer.json b/composer.json index 6b3040d..8759dcd 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,9 @@ "type": "project", "require": { "smarty/smarty": "~3.1", - "rg3/youtube-dl": "2015.10.24" + "rg3/youtube-dl": "2015.10.24", + "slim/slim": "~2.6.2", + "slim/views": "~0.1.3" }, "require-dev": { "symfony/var-dumper": "~2.7.6" diff --git a/composer.lock b/composer.lock index 2dec5bb..b4b3c99 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "b211e248137ada7cd1babc6c880fc4c5", - "content-hash": "30052efb27250d4c6eb0a5bb39518987", + "hash": "e2f86695cdc0cea75a4d55c83a8e5845", + "content-hash": "171a72e54b647ef8b67a785971c887fa", "packages": [ { "name": "rg3/youtube-dl", @@ -17,6 +17,105 @@ }, "type": "library" }, + { + "name": "slim/slim", + "version": "2.6.2", + "source": { + "type": "git", + "url": "https://github.com/slimphp/Slim.git", + "reference": "20a02782f76830b67ae56a5c08eb1f563c351a37" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/slimphp/Slim/zipball/20a02782f76830b67ae56a5c08eb1f563c351a37", + "reference": "20a02782f76830b67ae56a5c08eb1f563c351a37", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "suggest": { + "ext-mcrypt": "Required for HTTP cookie encryption" + }, + "type": "library", + "autoload": { + "psr-0": { + "Slim": "." + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Josh Lockhart", + "email": "info@joshlockhart.com", + "homepage": "http://www.joshlockhart.com/" + } + ], + "description": "Slim Framework, a PHP micro framework", + "homepage": "http://github.com/codeguy/Slim", + "keywords": [ + "microframework", + "rest", + "router" + ], + "time": "2015-03-08 18:41:17" + }, + { + "name": "slim/views", + "version": "0.1.3", + "source": { + "type": "git", + "url": "https://github.com/slimphp/Slim-Views.git", + "reference": "8561c785e55a39df6cb6f95c3aba3281a60ed5b0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/slimphp/Slim-Views/zipball/8561c785e55a39df6cb6f95c3aba3281a60ed5b0", + "reference": "8561c785e55a39df6cb6f95c3aba3281a60ed5b0", + "shasum": "" + }, + "require": { + "php": ">=5.3.0", + "slim/slim": ">=2.4.0" + }, + "suggest": { + "smarty/smarty": "Smarty templating system", + "twig/twig": "Twig templating system" + }, + "type": "library", + "autoload": { + "psr-4": { + "Slim\\Views\\": "./" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Josh Lockhart", + "email": "info@joshlockhart.com", + "homepage": "http://www.joshlockhart.com/" + }, + { + "name": "Andrew Smith", + "email": "a.smith@silentworks.co.uk", + "homepage": "http://thoughts.silentworks.co.uk/" + } + ], + "description": "Smarty and Twig View Parser package for the Slim Framework", + "homepage": "http://github.com/codeguy/Slim-Views", + "keywords": [ + "extensions", + "slimphp", + "templating" + ], + "time": "2014-12-09 23:48:51" + }, { "name": "smarty/smarty", "version": "v3.1.27", diff --git a/config.example.php b/config.example.php index 8b71239..f26c490 100644 --- a/config.example.php +++ b/config.example.php @@ -22,4 +22,3 @@ if (getenv('CONVERT')) { define('AVCONV', __DIR__.'/ffmpeg/ffmpeg'); define('MAINTENANCE', false); define('DISABLED', false); -define('BASE_URL', 'http://alltubedownload.net/'); diff --git a/disabled.php b/disabled.php deleted file mode 100644 index d7ee805..0000000 --- a/disabled.php +++ /dev/null @@ -1,22 +0,0 @@ - - * @author Olivier Haquette - * @license GNU General Public License http://www.gnu.org/licenses/gpl.html - * @link http://rudloff.pro - * */ -require_once 'common.php'; -if (!DISABLED) { - header('Location: index.php'); exit; -} -$smarty->display('head.tpl'); -$smarty->display('header.tpl'); -$smarty->display('disabled.tpl'); -$smarty->display('footer.tpl'); diff --git a/extractors.php b/extractors.php deleted file mode 100644 index e82168f..0000000 --- a/extractors.php +++ /dev/null @@ -1,23 +0,0 @@ - - * @author Olivier Haquette - * @license GNU General Public License http://www.gnu.org/licenses/gpl.html - * @link http://rudloff.pro - * */ -use Alltube\VideoDownload; -require_once 'common.php'; -$smarty->assign('class', 'extractors'); -$smarty->display('head.tpl'); -$smarty->display('header.tpl'); -$smarty->display('logo.tpl'); -$smarty->assign('extractors', VideoDownload::listExtractors()); -$smarty->display('extractors.tpl'); -$smarty->display('footer.tpl'); diff --git a/index.php b/index.php index 6be74ec..ada44bd 100644 --- a/index.php +++ b/index.php @@ -2,9 +2,9 @@ /** * PHP web interface for youtube-dl (http://rg3.github.com/youtube-dl/) * Index page - * + * * PHP Version 5.3.10 - * + * * @category Youtube-dl * @package Youtubedl * @author Pierre Rudloff @@ -12,9 +12,141 @@ * @license GNU General Public License http://www.gnu.org/licenses/gpl.html * @link http://rudloff.pro * */ +use Alltube\VideoDownload; require_once 'common.php'; -$smarty->assign('class', 'index'); -$smarty->display('head.tpl'); -$smarty->display('header.tpl'); -$smarty->display('index.tpl'); -$smarty->display('footer.tpl'); + +$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->render( + 'head.tpl', + array( + 'class'=>'video' + ) + ); + $app->render( + 'error.tpl', + array( + 'errors'=>$error + ) + ); + $app->render('footer.tpl'); + } +})->name('video'); +$app->run(); diff --git a/maintenance.php b/maintenance.php deleted file mode 100644 index fc64fec..0000000 --- a/maintenance.php +++ /dev/null @@ -1,22 +0,0 @@ - - * @author Olivier Haquette - * @license GNU General Public License http://www.gnu.org/licenses/gpl.html - * @link http://rudloff.pro - * */ -require_once 'common.php'; -if (!MAINTENANCE) { - header('Location: index.php'); exit; -} -$smarty->display('head.tpl'); -$smarty->display('header.tpl'); -$smarty->display('maintenance.tpl'); -$smarty->display('footer.tpl'); diff --git a/templates/head.tpl b/templates/head.tpl index a32c850..ab0dd81 100644 --- a/templates/head.tpl +++ b/templates/head.tpl @@ -4,20 +4,20 @@ - + AllTube Download - + - + diff --git a/templates/header.tpl b/templates/header.tpl index 4e10afe..dfa1df2 100644 --- a/templates/header.tpl +++ b/templates/header.tpl @@ -1,8 +1,8 @@
diff --git a/templates/index.tpl b/templates/index.tpl index 04dbfa1..dfd2e6d 100644 --- a/templates/index.tpl +++ b/templates/index.tpl @@ -1,7 +1,7 @@
-
+ @@ -20,10 +20,10 @@ {/if}
- See all supported websites + See all supported websites

Drag this to your bookmarks bar:

- Bookmarklet + Bookmarklet
diff --git a/templates/logo.tpl b/templates/logo.tpl index 15d3c3f..6d1ff44 100644 --- a/templates/logo.tpl +++ b/templates/logo.tpl @@ -1,4 +1,4 @@

- + AllTube Download

diff --git a/youtoubeur.php b/youtoubeur.php deleted file mode 100644 index f43478c..0000000 --- a/youtoubeur.php +++ /dev/null @@ -1,14 +0,0 @@ - - * @license GNU General Public License http://www.gnu.org/licenses/gpl.html - * @link http://rudloff.pro - * */ -header('Location: index.php');