alltube/controllers/FrontController.php

217 lines
6.3 KiB
PHP
Raw Normal View History

2015-10-29 21:32:36 +00:00
<?php
2015-10-31 14:50:32 +00:00
/**
* FrontController class
*
* 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
* */
2015-10-29 21:32:36 +00:00
namespace Alltube\Controller;
use Alltube\VideoDownload;
2015-10-31 14:42:25 +00:00
use Alltube\Config;
2015-10-31 14:50:32 +00:00
/**
* Main controller
*
* 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
* */
class FrontController
{
2015-10-29 21:32:36 +00:00
2015-10-31 14:50:32 +00:00
/**
* Display index page
* @return void
*/
static function index()
{
2015-10-29 21:32:36 +00:00
global $app;
2015-10-31 14:42:25 +00:00
$config = Config::getInstance();
2015-10-29 21:32:36 +00:00
$app->render(
'head.tpl',
array(
'class'=>'index'
)
);
$app->render(
'header.tpl'
);
$app->render(
'index.tpl',
array(
2015-10-31 14:42:25 +00:00
'convert'=>$config->convert
2015-10-29 21:32:36 +00:00
)
);
$app->render('footer.tpl');
}
2015-10-31 14:50:32 +00:00
/**
* Display a list of extractors
* @return void
*/
static function extractors()
{
2015-10-29 21:32:36 +00:00
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');
}
2015-10-31 14:50:32 +00:00
/**
* Dislay information about the video
* @return void
*/
static function video()
{
2015-10-29 21:32:36 +00:00
global $app;
2015-10-31 14:42:25 +00:00
$config = Config::getInstance();
2015-10-29 21:32:36 +00:00
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') {
ob_end_flush();
2015-10-29 21:32:36 +00:00
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).
2015-10-31 14:50:32 +00:00
' | '.$config->avconv.
' -v quiet -i - -f mp3 -vn pipe:1'
2015-10-29 21:32:36 +00:00
);
exit;
} else {
ob_end_flush();
2015-10-29 21:32:36 +00:00
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 '.$config->curl_params.' --user-agent '.escapeshellarg($UA).
2015-10-29 21:32:36 +00:00
' '.escapeshellarg($video->url).
2015-10-31 14:50:32 +00:00
' | '.$config->avconv.
' -v quiet -i - -f mp3 -vn pipe:1'
2015-10-29 21:32:36 +00:00
);
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');
}
}
2015-10-31 10:48:14 +00:00
2015-10-31 14:50:32 +00:00
/**
* Redirect to video file
* @return void
*/
static function redirect()
{
2015-10-31 10:48:14 +00:00
global $app;
if (isset($_GET["url"])) {
try {
$video = VideoDownload::getURL($_GET["url"]);
$app->redirect($video['url']);
} catch (\Exception $e) {
$app->response->headers->set('Content-Type', 'text/plain');
2015-11-22 18:31:38 +00:00
echo $e->getMessage().PHP_EOL;
2015-10-31 10:48:14 +00:00
}
}
}
2015-10-31 14:50:32 +00:00
/**
* Output JSON info about the video
* @return void
*/
static function json()
{
2015-10-31 10:48:14 +00:00
global $app;
if (isset($_GET["url"])) {
$app->response->headers->set('Content-Type', 'application/json');
try {
$video = VideoDownload::getJSON($_GET["url"]);
echo json_encode($video);
} catch (\Exception $e) {
echo json_encode(array('success'=>false, 'error'=>$e->getMessage()));
}
}
}
2015-10-29 21:32:36 +00:00
}