Use Slim framework (fixes #33)

This commit is contained in:
Pierre Rudloff 2015-10-29 21:19:40 +01:00
parent f85f07a77b
commit 299634b023
14 changed files with 255 additions and 113 deletions

View File

@ -8,3 +8,6 @@ AddType application/x-web-app-manifest+json .webapp
ExpiresByType image/svg+xml "access plus 1 week"
</ifmodule>
FileETag None
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

View File

@ -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
)
);

View File

@ -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"

103
composer.lock generated
View File

@ -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",

View File

@ -22,4 +22,3 @@ if (getenv('CONVERT')) {
define('AVCONV', __DIR__.'/ffmpeg/ffmpeg');
define('MAINTENANCE', false);
define('DISABLED', false);
define('BASE_URL', 'http://alltubedownload.net/');

View File

@ -1,22 +0,0 @@
<?php
/**
* 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 <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 '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');

View File

@ -1,23 +0,0 @@
<?php
/**
* PHP web interface for youtube-dl (http://rg3.github.com/youtube-dl/)
* List of all supported websites
*
* 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
* */
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');

146
index.php
View File

@ -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 <contact@rudloff.pro>
@ -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();

View File

@ -1,22 +0,0 @@
<?php
/**
* 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 <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 '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');

View File

@ -4,20 +4,20 @@
<meta charset="UTF-8" />
<meta name=viewport content="width=device-width, initial-scale=1">
<meta name="description" content="Easily download videos from Youtube, Dailymotion, Vimeo and other websites." />
<link rel="stylesheet" href="dist/main.css" />
<link rel="stylesheet" href="{siteUrl url='dist/main.css'}" />
<link rel="author" href="https://plus.google.com/110403274854419000481?rel=author" />
<link rel="author" href="https://plus.google.com/103696815796116179392?rel=author" />
<link href="https://plus.google.com/108799967445657477255" rel="publisher" />
<title itemprop="name">AllTube Download</title>
<meta itemprop="url" content="http://alltubedownload.net/" />
<link rel="icon" href="img/favicon.png" />
<link rel="icon" href="{siteUrl url='img/favicon.png'}" />
<meta property="og:url" content="http://www.alltubedownload.net/" />
<meta property="og:title" content="AllTube Download" />
<meta property="og:description" content="Easily download videos from Youtube, Dailymotion, Vimeo and other websites." />
<meta property="og:image" content="http://www.alltubedownload.net/img/logo.png" />
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content="AllTube Download" />
<meta name="twitter:image" content="http://www.alltubedownload.net/img/logo.png" />
<meta name="twitter:image" content="{siteUrl url='img/logo.png'}" />
<meta name="twitter:creator" content="@Tael67" />
<meta name="twitter:description" content="Easily download videos from Youtube, Dailymotion, Vimeo and other websites." />
<script type="text/javascript" src="https://www.gstatic.com/cv/js/sender/v1/cast_sender.js"></script>

View File

@ -1,8 +1,8 @@
<header>
<div class="social">
<a class="twitter" href="http://twitter.com/home?status={$base_url|urlencode}" target="_blank">
<a class="twitter" href="http://twitter.com/home?status={siteUrl|urlencode}" target="_blank">
Share on Twitter<div class="twittermask"></div></a>
<a class="facebook" href="https://www.facebook.com/sharer/sharer.php?u={$base_url|urlencode}" target="_blank">Share on Facebook<div class="facebookmask"></div></a>
<a class="facebook" href="https://www.facebook.com/sharer/sharer.php?u={siteUrl|urlencode}" target="_blank">Share on Facebook<div class="facebookmask"></div></a>
</div>
</header>
<div class="wrapper">

View File

@ -1,7 +1,7 @@
<div class="main">
<div><img itemprop="image" class="logo" src="img/logo.png"
alt="AllTube Download" width="328" height="284"></div>
<form action="api.php">
<form action="{urlFor name="video"}">
<label class="labelurl" for="url">
Copy here the URL of your video (Youtube, Dailymotion, etc.)
</label>
@ -20,10 +20,10 @@
{/if}
</div>
</form>
<a class="combatiblelink" href="extractors.php">See all supported websites</a>
<a class="combatiblelink" href="{urlFor name="extractors"}">See all supported websites</a>
<div id="bookmarklet">
<p> Drag this to your bookmarks bar: </p>
<a class="bookmarklet" href="javascript:window.location='{$base_url}/api.php?url='+encodeURIComponent(location.href);">Bookmarklet</a>
<a class="bookmarklet" href="javascript:window.location='{siteUrl url='api.php'}?url='+encodeURIComponent(location.href);">Bookmarklet</a>
</div>
</div>

View File

@ -1,4 +1,4 @@
<h1 class="logobis">
<a class="logocompatible" href="index.php">
<a class="logocompatible" href="{siteUrl}">
AllTube Download<span class="logocompatiblemask"><img src="img/logocompatiblemask.png" width="447" height="107" alt="" /></span>
</a></h1>

View File

@ -1,14 +0,0 @@
<?php
/**
* PHP web interface for youtube-dl (http://rg3.github.com/youtube-dl/)
* Old index file, now redirects to index.php
*
* 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
* */
header('Location: index.php');