Added trending page
This commit is contained in:
parent
e9b194217a
commit
51e27db867
7 changed files with 128 additions and 63 deletions
53
index.php
53
index.php
|
|
@ -3,6 +3,11 @@ require __DIR__ . "/vendor/autoload.php";
|
|||
|
||||
use Leaf\Blade;
|
||||
|
||||
function startStream (string $url) {
|
||||
$streamer = new \Sovit\TikTok\Stream();
|
||||
$streamer->stream($url);
|
||||
}
|
||||
|
||||
$app = new Leaf\App;
|
||||
|
||||
$app->get('/', function () use ($app) {
|
||||
|
|
@ -13,12 +18,46 @@ $app->get('/stream', function () {
|
|||
if (!isset($_GET['url'])) {
|
||||
die('You need to send a url!');
|
||||
}
|
||||
|
||||
// Start streamer
|
||||
$streamer = new \Sovit\TikTok\Stream();
|
||||
$streamer->stream($_GET['url']);
|
||||
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);
|
||||
}
|
||||
|
||||
});
|
||||
*/
|
||||
|
||||
$app->get("/@([^/]+)", function (string $username) {
|
||||
$cursor = 0;
|
||||
if (isset($_GET['cursor']) && is_numeric($_GET['cursor'])) {
|
||||
|
|
@ -26,9 +65,9 @@ $app->get("/@([^/]+)", function (string $username) {
|
|||
}
|
||||
$blade = new Blade('./views', './cache/views');
|
||||
$api = new \Sovit\TikTok\Api();
|
||||
$user = $api->getUserFeed($username, $cursor);
|
||||
if ($user) {
|
||||
echo $blade->render('user', ['user' => $user]);
|
||||
$feed = $api->getUserFeed($username, $cursor);
|
||||
if ($feed) {
|
||||
echo $blade->render('user', ['feed' => $feed]);
|
||||
} else {
|
||||
echo 'ERROR!';
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue