diff --git a/index.php b/index.php
index 75c7672..8a58b3f 100644
--- a/index.php
+++ b/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!';
}
diff --git a/scripts/user.js b/scripts/feed.js
similarity index 100%
rename from scripts/user.js
rename to scripts/feed.js
diff --git a/styles/user.css b/styles/feed.css
similarity index 100%
rename from styles/user.css
rename to styles/feed.css
diff --git a/views/feed.blade.php b/views/feed.blade.php
new file mode 100644
index 0000000..dda466a
--- /dev/null
+++ b/views/feed.blade.php
@@ -0,0 +1,52 @@
+