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_style = space
indent_size = 4 indent_size = 4
[**.blade.php]
indent_style = tab
indent_size = 2
[**.html] [**.html]
indent_style = tab indent_style = tab
indent_size = 2 indent_size = 2

View file

@ -1,10 +1,13 @@
{ {
"name": "pablouser1/tiktok-viewer", "name": "pablouser1/tiktok-viewer",
"description": "An alternative frontend for TikTok",
"version": "1.0.0",
"license": "AGPL-3.0-or-later",
"require": { "require": {
"leafs/leaf": "dev-v3.x-dev", "php": "^8.0.0",
"leafs/blade": "^1.2", "ext-curl": "*",
"ssovit/tiktok-api": "^2.0", "ssovit/tiktok-api": "^2.0",
"vlucas/phpdotenv": "^5.4", "bramus/router": "^1.6",
"php": "^8.0.0" "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", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "24a1a42f9512ff089db3e367de67ade4", "content-hash": "a272158b7b1fb157a2096739db8a1574",
"packages": [ "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", "name": "doctrine/inflector",
"version": "2.0.4", "version": "2.0.4",
@ -97,68 +148,6 @@
], ],
"time": "2021-10-22T20:16:43+00:00" "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", "name": "illuminate/bus",
"version": "v8.77.1", "version": "v8.77.1",
@ -699,73 +688,17 @@
"time": "2021-12-16T19:23:48+00:00" "time": "2021-12-16T19:23:48+00:00"
}, },
{ {
"name": "leafs/anchor", "name": "jenssegers/blade",
"version": "v1.1.1", "version": "v1.4.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/leafsphp/anchor.git", "url": "https://github.com/jenssegers/blade.git",
"reference": "30d6a5eec7f36baf1ddd6b15ed08ebbb0505cc65" "reference": "22a3700e9fc469c19dd1c5e5bd1b9138195e421f"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/leafsphp/anchor/zipball/30d6a5eec7f36baf1ddd6b15ed08ebbb0505cc65", "url": "https://api.github.com/repos/jenssegers/blade/zipball/22a3700e9fc469c19dd1c5e5bd1b9138195e421f",
"reference": "30d6a5eec7f36baf1ddd6b15ed08ebbb0505cc65", "reference": "22a3700e9fc469c19dd1c5e5bd1b9138195e421f",
"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",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -779,7 +712,7 @@
"type": "library", "type": "library",
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"Leaf\\": "src/" "Jenssegers\\Blade\\": "src/"
} }
}, },
"notification-url": "https://packagist.org/downloads/", "notification-url": "https://packagist.org/downloads/",
@ -788,212 +721,33 @@
], ],
"authors": [ "authors": [
{ {
"name": "Michael Darko", "name": "Jens Segers",
"email": "mickdd22@gmail.com", "homepage": "https://jenssegers.com"
"homepage": "https://mychi.netlify.com",
"role": "Developer"
} }
], ],
"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": [ "keywords": [
"blade", "blade",
"laravel", "laravel",
"leaf",
"leafMVC",
"render", "render",
"template", "template",
"view" "view"
], ],
"support": { "support": {
"source": "https://github.com/leafsphp/blade/tree/v1.2.4" "issues": "https://github.com/jenssegers/blade/issues",
}, "source": "https://github.com/jenssegers/blade/tree/v1.4.0"
"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"
}, },
"funding": [ "funding": [
{ {
"url": "https://opencollective.com/leaf", "url": "https://github.com/jenssegers",
"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",
"type": "github" "type": "github"
}, },
{ {
"url": "https://opencollective.com/leaf", "url": "https://opencollective.com/jenssegers-blade",
"type": "open_collective" "type": "open_collective"
} }
], ],
"time": "2021-12-31T12:54:44+00:00" "time": "2020-09-17T08:25:26+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"
}, },
{ {
"name": "nesbot/carbon", "name": "nesbot/carbon",
@ -1091,77 +845,6 @@
], ],
"time": "2021-12-03T14:59:52+00:00" "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", "name": "psr/container",
"version": "1.1.2", "version": "1.1.2",
@ -1437,85 +1120,6 @@
], ],
"time": "2021-12-15T11:06:13+00:00" "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", "name": "symfony/polyfill-mbstring",
"version": "v1.23.1", "version": "v1.23.1",
@ -1852,86 +1456,6 @@
], ],
"time": "2021-09-07T12:43:40+00:00" "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", "name": "voku/portable-ascii",
"version": "1.5.6", "version": "1.5.6",
@ -2010,13 +1534,12 @@
"packages-dev": [], "packages-dev": [],
"aliases": [], "aliases": [],
"minimum-stability": "stable", "minimum-stability": "stable",
"stability-flags": { "stability-flags": [],
"leafs/leaf": 20
},
"prefer-stable": false, "prefer-stable": false,
"prefer-lowest": false, "prefer-lowest": false,
"platform": { "platform": {
"php": "^8.0.0" "php": "^8.0.0",
"ext-curl": "*"
}, },
"platform-dev": [], "platform-dev": [],
"plugin-api-version": "2.2.0" "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 <?php
require __DIR__ . "/vendor/autoload.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) { function getApi(array $proxy_elements): \Sovit\TikTok\Api {
$streamer = new \Sovit\TikTok\Stream(); $options = [];
$streamer->stream($url); 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) { $router->get('/', function () {
$app->response()->page('./views/home.html'); 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'])) { if (!isset($_GET['url'])) {
die('You need to send a 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['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!';
}
}); });
$app->get("/trending", function () { $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!');
}
$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);
});
$router->get("/trending", function () use ($proxy_elements) {
$cursor = 0; $cursor = 0;
if (isset($_GET['cursor']) && is_numeric($_GET['cursor'])) { if (isset($_GET['cursor']) && is_numeric($_GET['cursor'])) {
$cursor = (int) $_GET['cursor']; $cursor = (int) $_GET['cursor'];
} }
$blade = new Blade('./views', './cache/views'); $blade = new Blade('./views', './cache/views');
$api = new \Sovit\TikTok\Api(); $api = getApi($proxy_elements);
$feed = $api->getTrendingFeed($cursor); $feed = $api->getTrendingFeed($cursor);
if ($feed) { if ($feed) {
echo $blade->render('trending', ['feed' => $feed]); echo $blade->render('trending', ['feed' => $feed]);
@ -36,35 +98,13 @@ $app->get("/trending", function () {
} }
}); });
/* CURRENTLY NOT WORKING $router->get("/@([^/]+)", function (string $username) use ($proxy_elements) {
$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; $cursor = 0;
if (isset($_GET['cursor']) && is_numeric($_GET['cursor'])) { if (isset($_GET['cursor']) && is_numeric($_GET['cursor'])) {
$cursor = (int) $_GET['cursor']; $cursor = (int) $_GET['cursor'];
} }
$blade = new Blade('./views', './cache/views'); $blade = new Blade('./views', './cache/views');
$api = new \Sovit\TikTok\Api(); $api = getApi($proxy_elements);
$feed = $api->getUserFeed($username, $cursor); $feed = $api->getUserFeed($username, $cursor);
if ($feed) { if ($feed) {
echo $blade->render('user', ['feed' => $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

@ -2,14 +2,15 @@
<div class="columns is-multiline is-vcentered"> <div class="columns is-multiline is-vcentered">
@foreach ($feed->items as $item) @foreach ($feed->items as $item)
<div class="column is-one-quarter"> <div class="column is-one-quarter">
<a id="{{$item->id}}" href="#{{$item->id}}" class="clickable-img" data-video_url="{{ $item->video->playAddr }}" <a id="{{$item->id}}" href="#{{$item->id}}" class="clickable-img"
data-video_download="{{ $item->video->downloadAddr }}" data-video_url="./stream?url={{ $item->video->playAddr }}"
data-video_download="./stream?url={{urlencode($item->video->downloadAddr)}}"
data-desc="{{ $item->desc }}" data-desc="{{ $item->desc }}"
data-video_width="{{ $item->video->width }}" data-video_width="{{ $item->video->width }}"
data-video_height="{{ $item->video->height }}" data-video_height="{{ $item->video->height }}"
data-music_title="{{ $item->music->title }}" data-music_title="{{ $item->music->title }}"
data-music_url="{{ $item->music->playUrl }}"> data-music_url="./audios?url={{ urlencode($item->music->playUrl) }}">
<img src="{{ $item->video->originCover }}"/> <img loading="lazy" src="./images?url={{ urlencode($item->video->originCover) }}"/>
</a> </a>
</div> </div>
@endforeach @endforeach
@ -40,7 +41,7 @@
<div class="container"> <div class="container">
<a id="download_button" target="_blank" class="button is-info" href="" download>Download</a> <a id="download_button" target="_blank" class="button is-info" href="" download>Download</a>
<p id="audio_title"></p> <p id="audio_title"></p>
<audio id="audio" controls></audio> <audio id="audio" controls preload="none"></audio>
<div class="buttons"> <div class="buttons">
<button id="back-button" class="button is-danger">Back</button> <button id="back-button" class="button is-danger">Back</button>
<button id="next-button" class="button is-success">Next</button> <button id="next-button" class="button is-success">Next</button>

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

@ -16,6 +16,8 @@
</div> </div>
</div> </div>
</section> </section>
@include('navbar')
@include('feed') @include('feed')
@include('footer')
</body> </body>
</html> </html>

View file

@ -9,6 +9,7 @@
<link rel="stylesheet" href="../styles/feed.css"> <link rel="stylesheet" href="../styles/feed.css">
</head> </head>
<body> <body>
@include('navbar')
<section class="hero is-primary"> <section class="hero is-primary">
<div class="hero-body"> <div class="hero-body">
<div class="container"> <div class="container">
@ -18,5 +19,6 @@
</div> </div>
</section> </section>
@include('feed') @include('feed')
@include('footer')
</body> </body>
</html> </html>