Added trending page
This commit is contained in:
parent
e9b194217a
commit
51e27db867
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!';
|
||||
}
|
||||
|
|
52
views/feed.blade.php
Normal file
52
views/feed.blade.php
Normal file
|
@ -0,0 +1,52 @@
|
|||
<section class="section">
|
||||
<div class="columns is-multiline is-vcentered">
|
||||
@foreach ($feed->items as $item)
|
||||
<div class="column is-one-quarter">
|
||||
<a id="{{$item->id}}" href="#{{$item->id}}" class="clickable-img" data-video_url="{{ $item->video->playAddr }}"
|
||||
data-video_download="{{ $item->video->downloadAddr }}"
|
||||
data-desc="{{ $item->desc }}"
|
||||
data-video_width="{{ $item->video->width }}"
|
||||
data-video_height="{{ $item->video->height }}"
|
||||
data-music_title="{{ $item->music->title }}"
|
||||
data-music_url="{{ $item->music->playUrl }}">
|
||||
<img src="{{ $item->video->originCover }}"/>
|
||||
</a>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
<div class="buttons">
|
||||
@isset ($_GET['cursor'])
|
||||
<a class="button is-danger" href="?cursor=0">First</a>
|
||||
@endisset
|
||||
<a class="button is-danger" href="javascript:history.back()">Back</a>
|
||||
@if ($feed->hasMore)
|
||||
<a class="button is-success" href="?cursor={{ $feed->maxCursor }}">Next</a>
|
||||
@else
|
||||
<a class="button is-success" disabled title="No more videos available">Next</a>
|
||||
@endif
|
||||
</div>
|
||||
</section>
|
||||
<div id="modal" class="modal">
|
||||
<div id="modal-background" class="modal-background"></div>
|
||||
<div class="modal-card">
|
||||
<header class="modal-card-head">
|
||||
<button id="modal-close" class="delete" aria-label="close"></button>
|
||||
<p class="modal-card-title" id="item_title"></p>
|
||||
</header>
|
||||
<section class="modal-card-body has-text-centered" style="overflow: hidden;">
|
||||
<video id="video" controls preload="none"></video>
|
||||
</section>
|
||||
<footer class="modal-card-foot has-text-centered">
|
||||
<div class="container">
|
||||
<a id="download_button" target="_blank" class="button is-info" href="" download>Download</a>
|
||||
<p id="audio_title"></p>
|
||||
<audio id="audio" controls></audio>
|
||||
<div class="buttons">
|
||||
<button id="back-button" class="button is-danger">Back</button>
|
||||
<button id="next-button" class="button is-success">Next</button>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
</div>
|
||||
<script src="../scripts/feed.js"></script>
|
|
@ -15,6 +15,7 @@
|
|||
<div class="container has-text-centered">
|
||||
<p class="title">Welcome to TikTok Viewer!</p>
|
||||
<p class="subtitle">Alternative TikTok Frontend</p>
|
||||
<p>Search user:</p>
|
||||
<form id="username_form">
|
||||
<div class="field has-addons has-addons-centered">
|
||||
<div class="control">
|
||||
|
@ -25,6 +26,9 @@
|
|||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<hr />
|
||||
<p>Trending:</p>
|
||||
<a class="button is-success" href="./trending">Go</a>
|
||||
</div>
|
||||
</section>
|
||||
<script>
|
||||
|
|
21
views/trending.blade.php
Normal file
21
views/trending.blade.php
Normal file
|
@ -0,0 +1,21 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>Trending - TikTok</title>
|
||||
<link rel="stylesheet" href="https://unpkg.com/bulmaswatch/superhero/bulmaswatch.min.css">
|
||||
<link rel="stylesheet" href="../styles/feed.css">
|
||||
</head>
|
||||
<body>
|
||||
<section class="hero is-primary">
|
||||
<div class="hero-body">
|
||||
<div class="container">
|
||||
<p class="title">Trending page</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
@include('feed')
|
||||
</body>
|
||||
</html>
|
|
@ -4,70 +4,19 @@
|
|||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>{{ $user->info->detail->user->nickname }} - TikTok</title>
|
||||
<title>{{ $feed->info->detail->user->nickname }} - TikTok</title>
|
||||
<link rel="stylesheet" href="https://unpkg.com/bulmaswatch/superhero/bulmaswatch.min.css">
|
||||
<link rel="stylesheet" href="../styles/user.css">
|
||||
<link rel="stylesheet" href="../styles/feed.css">
|
||||
</head>
|
||||
<body>
|
||||
<section class="hero is-primary">
|
||||
<div class="hero-body">
|
||||
<div class="container">
|
||||
<p class="title">{{ $user->info->detail->user->uniqueId }}'s profile</p>
|
||||
<p class="subtitle">{{ $user->info->detail->user->signature }}</p>
|
||||
<p class="title">{{ $feed->info->detail->user->uniqueId }}'s profile</p>
|
||||
<p class="subtitle">{{ $feed->info->detail->user->signature }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<section class="section">
|
||||
<div class="columns is-multiline is-vcentered">
|
||||
@foreach ($user->items as $item)
|
||||
<div class="column is-one-quarter">
|
||||
<a id="{{$item->id}}" href="#{{$item->id}}" class="clickable-img" data-video_url="{{ $item->video->playAddr }}"
|
||||
data-video_download="{{ $item->video->downloadAddr }}"
|
||||
data-desc="{{ $item->desc }}"
|
||||
data-video_width="{{ $item->video->width }}"
|
||||
data-video_height="{{ $item->video->height }}"
|
||||
data-music_title="{{ $item->music->title }}"
|
||||
data-music_url="{{ $item->music->playUrl }}">
|
||||
<img src="{{ $item->video->originCover }}"/>
|
||||
</a>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
<div class="buttons">
|
||||
@isset ($_GET['cursor'])
|
||||
<a class="button is-danger" href="?cursor=0">First</a>
|
||||
@endisset
|
||||
<a class="button is-danger" href="javascript:history.back()">Back</a>
|
||||
@if ($user->hasMore)
|
||||
<a class="button is-success" href="?cursor={{ $user->maxCursor }}">Next</a>
|
||||
@else
|
||||
<a class="button is-success" disabled title="No more videos available">Next</a>
|
||||
@endif
|
||||
</div>
|
||||
</section>
|
||||
<div id="modal" class="modal">
|
||||
<div id="modal-background" class="modal-background"></div>
|
||||
<div class="modal-card">
|
||||
<header class="modal-card-head">
|
||||
<button id="modal-close" class="delete" aria-label="close"></button>
|
||||
<p class="modal-card-title" id="item_title"></p>
|
||||
</header>
|
||||
<section class="modal-card-body has-text-centered" style="overflow: hidden;">
|
||||
<video id="video" controls preload="none"></video>
|
||||
</section>
|
||||
<footer class="modal-card-foot has-text-centered">
|
||||
<div class="container">
|
||||
<a id="download_button" target="_blank" class="button is-info" href="" download>Download</a>
|
||||
<p id="audio_title"></p>
|
||||
<audio id="audio" controls></audio>
|
||||
<div class="buttons">
|
||||
<button id="back-button" class="button is-danger">Back</button>
|
||||
<button id="next-button" class="button is-success">Next</button>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
</div>
|
||||
<script src="../scripts/user.js"></script>
|
||||
@include('feed')
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in a new issue