Use Slim for everything

This commit is contained in:
Pierre Rudloff 2015-10-31 11:48:14 +01:00
parent 78670d73a5
commit 51432dc53e
4 changed files with 34 additions and 48 deletions

View file

@ -134,4 +134,30 @@ class FrontController {
$app->render('footer.tpl');
}
}
static function redirect() {
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');
echo $e->getMessage();
}
}
}
static function json() {
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()));
}
}
}
}

View file

@ -37,4 +37,12 @@ $app->get(
'/video',
array('Alltube\Controller\FrontController', 'video')
)->name('video');
$app->get(
'/redirect',
array('Alltube\Controller\FrontController', 'redirect')
);
$app->get(
'/json',
array('Alltube\Controller\FrontController', 'json')
);
$app->run();

View file

@ -1,24 +0,0 @@
<?php
/**
* PHP web interface for youtube-dl (http://rg3.github.com/youtube-dl/)
* JSON API
*
* 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
* */
use Alltube\VideoDownload;
require_once 'common.php';
if (isset($_GET["url"])) {
header('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()));
}
}

View file

@ -1,24 +0,0 @@
<?php
/**
* PHP web interface for youtube-dl (http://rg3.github.com/youtube-dl/)
* Redirect to video in best format
*
* 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
* */
use Alltube\VideoDownload;
require_once 'common.php';
if (isset($_GET["url"])) {
try {
$video = VideoDownload::getURL($_GET["url"]);
header('Location: '.$video['url']);
} catch (Exception $e) {
header('Content-Type: text/plain');
echo $e->getMessage();
}
}