Settings, removed leaf and tiktok proxy

This commit is contained in:
Pablo Ferreiro 2022-01-02 17:39:22 +01:00
parent de4e726e1f
commit 042e36fffc
No known key found for this signature in database
GPG key ID: 41FBCE65B779FA24
15 changed files with 370 additions and 663 deletions

View file

@ -31,6 +31,10 @@ indent_size = 2
indent_style = space
indent_size = 4
[**.blade.php]
indent_style = tab
indent_size = 2
[**.html]
indent_style = tab
indent_size = 2

View file

@ -1,10 +1,13 @@
{
"name": "pablouser1/tiktok-viewer",
"description": "An alternative frontend for TikTok",
"version": "1.0.0",
"license": "AGPL-3.0-or-later",
"require": {
"leafs/leaf": "dev-v3.x-dev",
"leafs/blade": "^1.2",
"php": "^8.0.0",
"ext-curl": "*",
"ssovit/tiktok-api": "^2.0",
"vlucas/phpdotenv": "^5.4",
"php": "^8.0.0"
"bramus/router": "^1.6",
"jenssegers/blade": "^1.4"
}
}

617
composer.lock generated
View file

@ -4,8 +4,59 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "24a1a42f9512ff089db3e367de67ade4",
"content-hash": "a272158b7b1fb157a2096739db8a1574",
"packages": [
{
"name": "bramus/router",
"version": "1.6.1",
"source": {
"type": "git",
"url": "https://github.com/bramus/router.git",
"reference": "55657b76da8a0a509250fb55b9dd24e1aa237eba"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/bramus/router/zipball/55657b76da8a0a509250fb55b9dd24e1aa237eba",
"reference": "55657b76da8a0a509250fb55b9dd24e1aa237eba",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "~2.14",
"phpunit/php-code-coverage": "~2.0",
"phpunit/phpunit": "~4.8"
},
"type": "library",
"autoload": {
"psr-0": {
"Bramus": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Bram(us) Van Damme",
"email": "bramus@bram.us",
"homepage": "http://www.bram.us"
}
],
"description": "A lightweight and simple object oriented PHP Router",
"homepage": "https://github.com/bramus/router",
"keywords": [
"router",
"routing"
],
"support": {
"issues": "https://github.com/bramus/router/issues",
"source": "https://github.com/bramus/router/tree/1.6.1"
},
"time": "2021-11-18T19:24:07+00:00"
},
{
"name": "doctrine/inflector",
"version": "2.0.4",
@ -97,68 +148,6 @@
],
"time": "2021-10-22T20:16:43+00:00"
},
{
"name": "graham-campbell/result-type",
"version": "v1.0.4",
"source": {
"type": "git",
"url": "https://github.com/GrahamCampbell/Result-Type.git",
"reference": "0690bde05318336c7221785f2a932467f98b64ca"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/GrahamCampbell/Result-Type/zipball/0690bde05318336c7221785f2a932467f98b64ca",
"reference": "0690bde05318336c7221785f2a932467f98b64ca",
"shasum": ""
},
"require": {
"php": "^7.0 || ^8.0",
"phpoption/phpoption": "^1.8"
},
"require-dev": {
"phpunit/phpunit": "^6.5.14 || ^7.5.20 || ^8.5.19 || ^9.5.8"
},
"type": "library",
"autoload": {
"psr-4": {
"GrahamCampbell\\ResultType\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Graham Campbell",
"email": "hello@gjcampbell.co.uk",
"homepage": "https://github.com/GrahamCampbell"
}
],
"description": "An Implementation Of The Result Type",
"keywords": [
"Graham Campbell",
"GrahamCampbell",
"Result Type",
"Result-Type",
"result"
],
"support": {
"issues": "https://github.com/GrahamCampbell/Result-Type/issues",
"source": "https://github.com/GrahamCampbell/Result-Type/tree/v1.0.4"
},
"funding": [
{
"url": "https://github.com/GrahamCampbell",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/graham-campbell/result-type",
"type": "tidelift"
}
],
"time": "2021-11-21T21:41:47+00:00"
},
{
"name": "illuminate/bus",
"version": "v8.77.1",
@ -699,73 +688,17 @@
"time": "2021-12-16T19:23:48+00:00"
},
{
"name": "leafs/anchor",
"version": "v1.1.1",
"name": "jenssegers/blade",
"version": "v1.4.0",
"source": {
"type": "git",
"url": "https://github.com/leafsphp/anchor.git",
"reference": "30d6a5eec7f36baf1ddd6b15ed08ebbb0505cc65"
"url": "https://github.com/jenssegers/blade.git",
"reference": "22a3700e9fc469c19dd1c5e5bd1b9138195e421f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/leafsphp/anchor/zipball/30d6a5eec7f36baf1ddd6b15ed08ebbb0505cc65",
"reference": "30d6a5eec7f36baf1ddd6b15ed08ebbb0505cc65",
"shasum": ""
},
"type": "library",
"autoload": {
"psr-4": {
"Leaf\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Darko",
"email": "mickdd22@gmail.com",
"homepage": "https://mychi.netlify.app",
"role": "Developer"
}
],
"description": "Leaf PHP util module",
"homepage": "https://leafphp.netlify.app/#/",
"keywords": [
"framework",
"leaf",
"php",
"util"
],
"support": {
"issues": "https://github.com/leafsphp/anchor/issues",
"source": "https://github.com/leafsphp/anchor/tree/v1.1.1"
},
"funding": [
{
"url": "https://github.com/leafsphp",
"type": "github"
},
{
"url": "https://opencollective.com/leaf",
"type": "open_collective"
}
],
"time": "2021-12-16T09:05:13+00:00"
},
{
"name": "leafs/blade",
"version": "v1.2.4",
"source": {
"type": "git",
"url": "https://github.com/leafsphp/blade.git",
"reference": "4daec543d0aae91de03369cb90c742e95cb111ac"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/leafsphp/blade/zipball/4daec543d0aae91de03369cb90c742e95cb111ac",
"reference": "4daec543d0aae91de03369cb90c742e95cb111ac",
"url": "https://api.github.com/repos/jenssegers/blade/zipball/22a3700e9fc469c19dd1c5e5bd1b9138195e421f",
"reference": "22a3700e9fc469c19dd1c5e5bd1b9138195e421f",
"shasum": ""
},
"require": {
@ -779,7 +712,7 @@
"type": "library",
"autoload": {
"psr-4": {
"Leaf\\": "src/"
"Jenssegers\\Blade\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
@ -788,212 +721,33 @@
],
"authors": [
{
"name": "Michael Darko",
"email": "mickdd22@gmail.com",
"homepage": "https://mychi.netlify.com",
"role": "Developer"
"name": "Jens Segers",
"homepage": "https://jenssegers.com"
}
],
"description": "Leaf PHP Framework adaptation of jenssegers/blade package",
"description": "The standalone version of Laravel's Blade templating engine for use outside of Laravel.",
"keywords": [
"blade",
"laravel",
"leaf",
"leafMVC",
"render",
"template",
"view"
],
"support": {
"source": "https://github.com/leafsphp/blade/tree/v1.2.4"
},
"time": "2021-01-20T17:21:52+00:00"
},
{
"name": "leafs/http",
"version": "v1.1",
"source": {
"type": "git",
"url": "https://github.com/leafsphp/http.git",
"reference": "c2383c897ef46f9eebf5a3e6e9f9fe148222ca01"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/leafsphp/http/zipball/c2383c897ef46f9eebf5a3e6e9f9fe148222ca01",
"reference": "c2383c897ef46f9eebf5a3e6e9f9fe148222ca01",
"shasum": ""
},
"require": {
"leafs/anchor": "^1.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Leaf\\Http\\": "src"
},
"files": [
"src/functions.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Darko",
"email": "mickdd22@gmail.com",
"homepage": "https://mychi.netlify.app",
"role": "Developer"
}
],
"description": "Leaf PHP HTTP module.",
"homepage": "https://leafphp.netlify.app/#/",
"keywords": [
"framework",
"headers",
"http",
"leaf",
"php",
"request",
"response"
],
"support": {
"issues": "https://github.com/leafsphp/http/issues",
"source": "https://github.com/leafsphp/http/tree/v1.1"
"issues": "https://github.com/jenssegers/blade/issues",
"source": "https://github.com/jenssegers/blade/tree/v1.4.0"
},
"funding": [
{
"url": "https://opencollective.com/leaf",
"type": "open_collective"
}
],
"time": "2021-11-09T08:14:22+00:00"
},
{
"name": "leafs/leaf",
"version": "dev-v3.x-dev",
"source": {
"type": "git",
"url": "https://github.com/leafsphp/leaf.git",
"reference": "57507c739106deb29c18da7f1e8e874b43dc1c7a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/leafsphp/leaf/zipball/57507c739106deb29c18da7f1e8e874b43dc1c7a",
"reference": "57507c739106deb29c18da7f1e8e874b43dc1c7a",
"shasum": ""
},
"require": {
"leafs/anchor": "^1.1",
"leafs/http": "^1.1",
"leafs/router": "^0.1.4"
},
"require-dev": {
"pestphp/pest": "^1.21"
},
"type": "library",
"autoload": {
"psr-4": {
"Leaf\\": "src"
},
"files": [
"src/functions.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Darko",
"email": "mickdd22@gmail.com",
"homepage": "https://mychi.netlify.app",
"role": "Developer"
}
],
"description": "Simple, performant and powerful PHP micro-framework for rapid web app & API development",
"homepage": "https://leafphp.dev",
"keywords": [
"framework",
"leaf",
"microframework",
"php",
"rest",
"router"
],
"support": {
"issues": "https://github.com/leafsphp/leaf/issues",
"source": "https://github.com/leafsphp/leaf/tree/v3.x-dev"
},
"funding": [
{
"url": "https://github.com/leafsphp",
"url": "https://github.com/jenssegers",
"type": "github"
},
{
"url": "https://opencollective.com/leaf",
"url": "https://opencollective.com/jenssegers-blade",
"type": "open_collective"
}
],
"time": "2021-12-31T12:54:44+00:00"
},
{
"name": "leafs/router",
"version": "v0.1.4",
"source": {
"type": "git",
"url": "https://github.com/leafsphp/router.git",
"reference": "a8fcc8bdf5defd00ac73d2f26aa7aa9699af9190"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/leafsphp/router/zipball/a8fcc8bdf5defd00ac73d2f26aa7aa9699af9190",
"reference": "a8fcc8bdf5defd00ac73d2f26aa7aa9699af9190",
"shasum": ""
},
"require": {
"leafs/http": "^1.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Leaf\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Darko",
"email": "mickdd22@gmail.com",
"homepage": "https://mychi.netlify.app",
"role": "Developer"
}
],
"description": "Leaf router module for Leaf PHP.",
"homepage": "https://leafphp.netlify.app/#/modules/router",
"keywords": [
"framework",
"leaf",
"php",
"rest",
"router"
],
"support": {
"issues": "https://github.com/leafsphp/router/issues",
"source": "https://github.com/leafsphp/router/tree/v0.1.4"
},
"funding": [
{
"url": "https://opencollective.com/leaf",
"type": "open_collective"
}
],
"time": "2021-11-22T09:27:33+00:00"
"time": "2020-09-17T08:25:26+00:00"
},
{
"name": "nesbot/carbon",
@ -1091,77 +845,6 @@
],
"time": "2021-12-03T14:59:52+00:00"
},
{
"name": "phpoption/phpoption",
"version": "1.8.1",
"source": {
"type": "git",
"url": "https://github.com/schmittjoh/php-option.git",
"reference": "eab7a0df01fe2344d172bff4cd6dbd3f8b84ad15"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/schmittjoh/php-option/zipball/eab7a0df01fe2344d172bff4cd6dbd3f8b84ad15",
"reference": "eab7a0df01fe2344d172bff4cd6dbd3f8b84ad15",
"shasum": ""
},
"require": {
"php": "^7.0 || ^8.0"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.4.1",
"phpunit/phpunit": "^6.5.14 || ^7.5.20 || ^8.5.19 || ^9.5.8"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.8-dev"
}
},
"autoload": {
"psr-4": {
"PhpOption\\": "src/PhpOption/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "Johannes M. Schmitt",
"email": "schmittjoh@gmail.com",
"homepage": "https://github.com/schmittjoh"
},
{
"name": "Graham Campbell",
"email": "hello@gjcampbell.co.uk",
"homepage": "https://github.com/GrahamCampbell"
}
],
"description": "Option Type for PHP",
"keywords": [
"language",
"option",
"php",
"type"
],
"support": {
"issues": "https://github.com/schmittjoh/php-option/issues",
"source": "https://github.com/schmittjoh/php-option/tree/1.8.1"
},
"funding": [
{
"url": "https://github.com/GrahamCampbell",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/phpoption/phpoption",
"type": "tidelift"
}
],
"time": "2021-12-04T23:24:31+00:00"
},
{
"name": "psr/container",
"version": "1.1.2",
@ -1437,85 +1120,6 @@
],
"time": "2021-12-15T11:06:13+00:00"
},
{
"name": "symfony/polyfill-ctype",
"version": "v1.23.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-ctype.git",
"reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/46cd95797e9df938fdd2b03693b5fca5e64b01ce",
"reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
"suggest": {
"ext-ctype": "For best performance"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.23-dev"
},
"thanks": {
"name": "symfony/polyfill",
"url": "https://github.com/symfony/polyfill"
}
},
"autoload": {
"psr-4": {
"Symfony\\Polyfill\\Ctype\\": ""
},
"files": [
"bootstrap.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Gert de Pagter",
"email": "BackEndTea@gmail.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill for ctype functions",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"ctype",
"polyfill",
"portable"
],
"support": {
"source": "https://github.com/symfony/polyfill-ctype/tree/v1.23.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2021-02-19T12:13:01+00:00"
},
{
"name": "symfony/polyfill-mbstring",
"version": "v1.23.1",
@ -1852,86 +1456,6 @@
],
"time": "2021-09-07T12:43:40+00:00"
},
{
"name": "vlucas/phpdotenv",
"version": "v5.4.1",
"source": {
"type": "git",
"url": "https://github.com/vlucas/phpdotenv.git",
"reference": "264dce589e7ce37a7ba99cb901eed8249fbec92f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/264dce589e7ce37a7ba99cb901eed8249fbec92f",
"reference": "264dce589e7ce37a7ba99cb901eed8249fbec92f",
"shasum": ""
},
"require": {
"ext-pcre": "*",
"graham-campbell/result-type": "^1.0.2",
"php": "^7.1.3 || ^8.0",
"phpoption/phpoption": "^1.8",
"symfony/polyfill-ctype": "^1.23",
"symfony/polyfill-mbstring": "^1.23.1",
"symfony/polyfill-php80": "^1.23.1"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.4.1",
"ext-filter": "*",
"phpunit/phpunit": "^7.5.20 || ^8.5.21 || ^9.5.10"
},
"suggest": {
"ext-filter": "Required to use the boolean validator."
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "5.4-dev"
}
},
"autoload": {
"psr-4": {
"Dotenv\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Graham Campbell",
"email": "hello@gjcampbell.co.uk",
"homepage": "https://github.com/GrahamCampbell"
},
{
"name": "Vance Lucas",
"email": "vance@vancelucas.com",
"homepage": "https://github.com/vlucas"
}
],
"description": "Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.",
"keywords": [
"dotenv",
"env",
"environment"
],
"support": {
"issues": "https://github.com/vlucas/phpdotenv/issues",
"source": "https://github.com/vlucas/phpdotenv/tree/v5.4.1"
},
"funding": [
{
"url": "https://github.com/GrahamCampbell",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/vlucas/phpdotenv",
"type": "tidelift"
}
],
"time": "2021-12-12T23:22:04+00:00"
},
{
"name": "voku/portable-ascii",
"version": "1.5.6",
@ -2010,13 +1534,12 @@
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": {
"leafs/leaf": 20
},
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
"php": "^8.0.0"
"php": "^8.0.0",
"ext-curl": "*"
},
"platform-dev": [],
"plugin-api-version": "2.2.0"

16
helpers/domains.php Normal file
View file

@ -0,0 +1,16 @@
<?php
$domains = [
"image" => [
"p16-sign-va.tiktokcdn.com",
"p16-sign-sg.tiktokcdn.com",
"p77-sign-va.tiktokcdn.com",
"p77-sign-sg.tiktokcdn.com",
"p77-sign-sg-lite.tiktokcdn.com"
],
"video" => [
"v16-webapp.tiktok.com"
],
"audio" => [
"sf16-ies-music-va.tiktokcdn.com"
],
];

View file

@ -0,0 +1,2 @@
<?php
$proxy_elements = ['proxy-host', 'proxy-port', 'proxy-username', 'proxy-password'];

127
index.php
View file

@ -1,33 +1,95 @@
<?php
require __DIR__ . "/vendor/autoload.php";
require __DIR__ . "/helpers/domains.php";
require __DIR__ . "/helpers/settings_elements.php";
use Leaf\Blade;
use Jenssegers\Blade\Blade;
function startStream (string $url) {
$streamer = new \Sovit\TikTok\Stream();
$streamer->stream($url);
function getApi(array $proxy_elements): \Sovit\TikTok\Api {
$options = [];
if (in_array($proxy_elements, $_COOKIE)) {
foreach ($proxy_elements as $proxy_element) {
$options[$proxy_element] = $_COOKIE[$proxy_element];
}
}
$api = new \Sovit\TikTok\Api($options);
return $api;
}
$app = new Leaf\App;
$router = new \Bramus\Router\Router();
$app->get('/', function () use ($app) {
$app->response()->page('./views/home.html');
$router->get('/', function () {
http_response_code(302);
header('Location: ./home');
});
$app->get('/stream', function () {
$router->get('/home', function () {
$blade = new Blade('./views', './cache/views');
echo $blade->render('home');
});
$router->get('/images', function () use ($domains) {
if (!isset($_GET['url'])) {
die('You need to send a url!');
}
$url = $_GET['url'];
$host = parse_url($url, PHP_URL_HOST);
if (!filter_var($url, FILTER_VALIDATE_URL) || !in_array($host, $domains['image'])) {
die('Not a valid URL');
}
$img = file_get_contents($url, false, stream_context_create(['http' => ['ignore_errors' => true]]));
if ($img) {
header('Content-Type: image/jpeg');
echo $img;
} else {
echo 'Error while getting image!';
}
});
$router->get('/audios', function () use ($domains) {
if (!isset($_GET['url'])) {
die('You need to send a url!');
}
$url = $_GET['url'];
$host = parse_url($url, PHP_URL_HOST);
if (!filter_var($url, FILTER_VALIDATE_URL) || !in_array($host, $domains['audio'])) {
die('Not a valid URL');
}
$audio = file_get_contents($url, false, stream_context_create(['http' => ['ignore_errors' => true]]));
if ($audio) {
header('Content-Type: audio/mp3');
echo $audio;
} else {
echo 'Error while getting audio!';
}
});
$router->get('/stream', function () use ($domains) {
if (!isset($_GET['url'])) {
die('You need to send a url!');
}
startStream($_GET['url']);
$url = $_GET['url'];
$host = parse_url($url, PHP_URL_HOST);
if (!filter_var($url, FILTER_VALIDATE_URL) || !in_array($host, $domains['video'])) {
die('Not a valid URL');
}
header('Content-Disposition: attachment; filename="tiktok.mp4"');
$streamer = new \Sovit\TikTok\Stream();
$streamer->stream($url);
});
$app->get("/trending", function () {
$router->get("/trending", function () use ($proxy_elements) {
$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();
$api = getApi($proxy_elements);
$feed = $api->getTrendingFeed($cursor);
if ($feed) {
echo $blade->render('trending', ['feed' => $feed]);
@ -36,35 +98,13 @@ $app->get("/trending", function () {
}
});
/* 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) {
$router->get("/@([^/]+)", function (string $username) use ($proxy_elements) {
$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();
$api = getApi($proxy_elements);
$feed = $api->getUserFeed($username, $cursor);
if ($feed) {
echo $blade->render('user', ['feed' => $feed]);
@ -73,4 +113,19 @@ $app->get("/@([^/]+)", function (string $username) {
}
});
$app->run();
$router->get("/settings", function () use ($proxy_elements) {
$blade = new Blade('./views', './cache/views');
echo $blade->render('settings', ["proxy_elements" => $proxy_elements]);
});
$router->post("/settings", function () use ($proxy_elements) {
if (in_array($proxy_elements, $_POST)) {
foreach ($proxy_elements as $proxy_element) {
setcookie($proxy_element, $_POST[$proxy_element], time()+60*60*24*30, '/', '', true, true);
}
}
http_response_code(302);
header('Location: ./home');
});
$router->run();

6
scripts/navbar.js Normal file
View file

@ -0,0 +1,6 @@
const navbar_menu = document.getElementById('navbar-menu')
const burger = document.getElementById('navbar-burger')
burger.addEventListener('click', () => {
burger.classList.toggle('is-active')
navbar_menu.classList.toggle('is-active')
})

24
views/about.blade.php Normal file
View file

@ -0,0 +1,24 @@
<!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>About - TikTok</title>
<link rel="stylesheet" href="https://unpkg.com/bulmaswatch/superhero/bulmaswatch.min.css">
</head>
<body>
@include('navbar')
<section class="hero is-primary">
<div class="hero-body">
<div class="container">
<p class="title">About</p>
</div>
</div>
</section>
<section class="section">
<p>TODO</p>
</section>
@include('footer')
</body>
</html>

View file

@ -1,52 +1,53 @@
<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 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="./stream?url={{ $item->video->playAddr }}"
data-video_download="./stream?url={{urlencode($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="./audios?url={{ urlencode($item->music->playUrl) }}">
<img loading="lazy" src="./images?url={{ urlencode($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 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 preload="none"></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>

7
views/footer.blade.php Normal file
View file

@ -0,0 +1,7 @@
<footer class="footer">
<div class="content">
<p class="has-text-centered">
Made with <span style="color: #e25555;">&#9829;</span> in <a href="https://github.com/pablouser1/tiktok-viewer">Github</a>
</p>
</div>
</footer>

View file

@ -10,7 +10,8 @@
</head>
<body>
<section class="hero is-fullheight">
@include('navbar')
<section class="hero is-fullheight-with-navbar">
<div class="hero-body">
<div class="container has-text-centered">
<p class="title">Welcome to TikTok Viewer!</p>
@ -30,6 +31,10 @@
<p>Trending:</p>
<a class="button is-success" href="./trending">Go</a>
</div>
</div>
<div class="hero-foot">
@include('footer')
</div>
</section>
<script>
const goToUser = (e) => {

17
views/navbar.blade.php Normal file
View file

@ -0,0 +1,17 @@
<nav class="navbar" role="navigation" aria-label="main navigation">
<div class="navbar-brand">
<a role="button" id="navbar-burger" class="navbar-burger" aria-label="menu" aria-expanded="false">
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
</div>
<div id="navbar-menu" class="navbar-menu">
<div class="navbar-start">
<a href="./home" class="navbar-item">Home</a>
<a href="./settings" class="navbar-item">Settings</a>
</div>
</div>
</nav>
<script src="./scripts/navbar.js"></script>

40
views/settings.blade.php Normal file
View file

@ -0,0 +1,40 @@
<!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>Settings - TikTok</title>
<link rel="stylesheet" href="https://unpkg.com/bulmaswatch/superhero/bulmaswatch.min.css">
</head>
<body>
@include('navbar')
<section class="hero is-primary">
<div class="hero-body">
<div class="container">
<p class="title">Settings</p>
</div>
</div>
</section>
<section class="section">
<!-- Proxy settings -->
<p class="title">Proxy</p>
<form action="./settings" method="POST">
@foreach ( $proxy_elements as $element)
<div class="field">
<label class="label">{{ $element }}</label>
<div class="control">
<input name="{{ $element }}" class="input" value="{{ isset($_COOKIE[$element]) ? $_COOKIE[$element] : ''}}" required />
</div>
</div>
@endforeach
<div class="field">
<div class="control">
<button class="button is-success" type="submit">Submit</button>
</div>
</div>
</form>
</section>
@include('footer')
</body>
</html>

View file

@ -1,21 +1,23 @@
<!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">
<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')
<section class="hero is-primary">
<div class="hero-body">
<div class="container">
<p class="title">Trending page</p>
</div>
</div>
</section>
@include('navbar')
@include('feed')
@include('footer')
</body>
</html>

View file

@ -1,22 +1,24 @@
<!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>{{ $feed->info->detail->user->nickname }} - TikTok</title>
<link rel="stylesheet" href="https://unpkg.com/bulmaswatch/superhero/bulmaswatch.min.css">
<link rel="stylesheet" href="../styles/feed.css">
<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>{{ $feed->info->detail->user->nickname }} - 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">{{ $feed->info->detail->user->uniqueId }}'s profile</p>
<p class="subtitle">{{ $feed->info->detail->user->signature }}</p>
</div>
</div>
</section>
@include('feed')
@include('navbar')
<section class="hero is-primary">
<div class="hero-body">
<div class="container">
<p class="title">{{ $feed->info->detail->user->uniqueId }}'s profile</p>
<p class="subtitle">{{ $feed->info->detail->user->signature }}</p>
</div>
</div>
</section>
@include('feed')
@include('footer')
</body>
</html>