proxitok/index.php

77 lines
1.7 KiB
PHP
Raw Normal View History

2022-01-01 19:14:57 +00:00
<?php
require __DIR__ . "/vendor/autoload.php";
use Leaf\Blade;
2022-01-01 23:42:03 +00:00
function startStream (string $url) {
$streamer = new \Sovit\TikTok\Stream();
$streamer->stream($url);
}
2022-01-01 19:14:57 +00:00
$app = new Leaf\App;
$app->get('/', function () use ($app) {
$app->response()->page('./views/home.html');
});
2022-01-01 23:06:00 +00:00
$app->get('/stream', function () {
if (!isset($_GET['url'])) {
die('You need to send a url!');
}
2022-01-01 23:42:03 +00:00
startStream($_GET['url']);
});
$app->get("/trending", function () {
$cursor = 0;
if (isset($_GET['cursor']) && is_numeric($_GET['cursor'])) {
$cursor = (int) $_GET['cursor'];
}
$blade = new Blade('./views', './cache/views');
$api = new \Sovit\TikTok\Api();
$feed = $api->getTrendingFeed($cursor);
if ($feed) {
echo $blade->render('trending', ['feed' => $feed]);
} else {
echo 'ERROR!';
}
});
/* CURRENTLY NOT WORKING
$app->get('/videos', function () {
if (!isset($_GET['id'])) {
die('You need to send an id param!');
}
$item = $_GET['id'];
$api = new \Sovit\TikTok\Api();
// Using an url
if (filter_var($item, FILTER_VALIDATE_URL)) {
$feed = $api->getVideoByUrl($item);
} else {
// Assume is an id
$feed = $api->getVideoByID($item);
}
if ($feed) {
var_dump($feed);
}
2022-01-01 23:06:00 +00:00
});
2022-01-01 23:42:03 +00:00
*/
2022-01-01 23:06:00 +00:00
$app->get("/@([^/]+)", function (string $username) {
2022-01-01 19:48:42 +00:00
$cursor = 0;
if (isset($_GET['cursor']) && is_numeric($_GET['cursor'])) {
$cursor = (int) $_GET['cursor'];
}
2022-01-01 19:14:57 +00:00
$blade = new Blade('./views', './cache/views');
$api = new \Sovit\TikTok\Api();
2022-01-01 23:42:03 +00:00
$feed = $api->getUserFeed($username, $cursor);
if ($feed) {
echo $blade->render('user', ['feed' => $feed]);
2022-01-01 19:14:57 +00:00
} else {
echo 'ERROR!';
}
});
$app->run();