diff --git a/controllers/FrontController.php b/controllers/FrontController.php index a7f27f0..2d0cf96 100644 --- a/controllers/FrontController.php +++ b/controllers/FrontController.php @@ -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())); + } + } + } } diff --git a/index.php b/index.php index 2b4ce3e..3deadb5 100644 --- a/index.php +++ b/index.php @@ -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(); diff --git a/json.php b/json.php deleted file mode 100644 index 025c2a6..0000000 --- a/json.php +++ /dev/null @@ -1,24 +0,0 @@ - - * @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())); - } -} diff --git a/redirect.php b/redirect.php deleted file mode 100644 index 20fff23..0000000 --- a/redirect.php +++ /dev/null @@ -1,24 +0,0 @@ - - * @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(); - } -}