2022-01-01 14:14:57 -05:00
|
|
|
<?php
|
|
|
|
require __DIR__ . "/vendor/autoload.php";
|
2022-01-02 11:39:22 -05:00
|
|
|
require __DIR__ . "/helpers/domains.php";
|
|
|
|
require __DIR__ . "/helpers/settings_elements.php";
|
2022-01-03 07:43:22 -05:00
|
|
|
use Steampixel\Route;
|
2022-01-01 14:14:57 -05:00
|
|
|
|
2022-01-03 07:43:22 -05:00
|
|
|
// LOAD DOTENV
|
|
|
|
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
|
|
|
|
$dotenv->load();
|
2022-01-01 14:14:57 -05:00
|
|
|
|
2022-01-02 11:39:22 -05:00
|
|
|
function getApi(array $proxy_elements): \Sovit\TikTok\Api {
|
|
|
|
$options = [];
|
2022-01-03 07:43:22 -05:00
|
|
|
// Proxy config
|
2022-01-02 11:39:22 -05:00
|
|
|
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;
|
2022-01-01 18:42:03 -05:00
|
|
|
}
|
|
|
|
|
2022-01-03 07:43:22 -05:00
|
|
|
function getLatte(): \Latte\Engine {
|
|
|
|
$latte = new Latte\Engine;
|
|
|
|
$latte->setTempDirectory('./cache/views');
|
|
|
|
return $latte;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getView(string $template): string {
|
|
|
|
return "./views/{$template}.latte";
|
|
|
|
}
|
2022-01-02 11:39:22 -05:00
|
|
|
|
2022-01-03 07:43:22 -05:00
|
|
|
Route::add('/', function () {
|
2022-01-02 11:39:22 -05:00
|
|
|
http_response_code(302);
|
|
|
|
header('Location: ./home');
|
|
|
|
});
|
|
|
|
|
2022-01-03 07:43:22 -05:00
|
|
|
Route::add('/home', function () {
|
|
|
|
$latte = getLatte();
|
|
|
|
$latte->render('./views/home.latte');
|
2022-01-02 11:39:22 -05:00
|
|
|
});
|
2022-01-01 14:14:57 -05:00
|
|
|
|
2022-01-03 07:43:22 -05:00
|
|
|
Route::add('/images', function () use ($domains) {
|
2022-01-02 11:39:22 -05:00
|
|
|
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');
|
2022-01-03 07:43:22 -05:00
|
|
|
return $img;
|
2022-01-02 11:39:22 -05:00
|
|
|
} else {
|
2022-01-03 07:43:22 -05:00
|
|
|
return 'Error while getting image!';
|
2022-01-02 11:39:22 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-01-03 07:43:22 -05:00
|
|
|
Route::add('/audios', function () use ($domains) {
|
2022-01-02 11:39:22 -05:00
|
|
|
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');
|
2022-01-03 07:43:22 -05:00
|
|
|
return $audio;
|
2022-01-02 11:39:22 -05:00
|
|
|
} else {
|
2022-01-03 07:43:22 -05:00
|
|
|
return 'Error while getting audio!';
|
2022-01-02 11:39:22 -05:00
|
|
|
}
|
2022-01-01 14:14:57 -05:00
|
|
|
});
|
|
|
|
|
2022-01-03 07:43:22 -05:00
|
|
|
Route::add('/stream', function () use ($domains) {
|
2022-01-01 18:06:00 -05:00
|
|
|
if (!isset($_GET['url'])) {
|
|
|
|
die('You need to send a url!');
|
|
|
|
}
|
2022-01-02 11:39:22 -05:00
|
|
|
|
|
|
|
$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');
|
|
|
|
}
|
|
|
|
|
2022-01-03 07:43:22 -05:00
|
|
|
if (isset($_GET['download'])) {
|
|
|
|
header('Content-Disposition: attachment; filename="tiktok.mp4"');
|
|
|
|
}
|
2022-01-02 11:39:22 -05:00
|
|
|
|
|
|
|
$streamer = new \Sovit\TikTok\Stream();
|
|
|
|
$streamer->stream($url);
|
2022-01-01 18:42:03 -05:00
|
|
|
});
|
|
|
|
|
2022-01-03 07:43:22 -05:00
|
|
|
Route::add("/trending", function () use ($proxy_elements) {
|
2022-01-01 18:42:03 -05:00
|
|
|
$cursor = 0;
|
|
|
|
if (isset($_GET['cursor']) && is_numeric($_GET['cursor'])) {
|
|
|
|
$cursor = (int) $_GET['cursor'];
|
|
|
|
}
|
2022-01-03 07:43:22 -05:00
|
|
|
$latte = getLatte();
|
2022-01-02 11:39:22 -05:00
|
|
|
$api = getApi($proxy_elements);
|
2022-01-01 18:42:03 -05:00
|
|
|
$feed = $api->getTrendingFeed($cursor);
|
|
|
|
if ($feed) {
|
2022-01-03 07:43:22 -05:00
|
|
|
$latte->render(getView('trending'), ['feed' => $feed]);
|
2022-01-01 18:42:03 -05:00
|
|
|
} else {
|
2022-01-03 07:43:22 -05:00
|
|
|
return 'ERROR!';
|
2022-01-01 18:42:03 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-01-03 07:43:22 -05:00
|
|
|
Route::add("/@([^/]+)", function (string $username) use ($proxy_elements) {
|
2022-01-01 14:48:42 -05:00
|
|
|
$cursor = 0;
|
|
|
|
if (isset($_GET['cursor']) && is_numeric($_GET['cursor'])) {
|
|
|
|
$cursor = (int) $_GET['cursor'];
|
|
|
|
}
|
2022-01-03 07:43:22 -05:00
|
|
|
$latte = getLatte();
|
2022-01-02 11:39:22 -05:00
|
|
|
$api = getApi($proxy_elements);
|
2022-01-01 18:42:03 -05:00
|
|
|
$feed = $api->getUserFeed($username, $cursor);
|
|
|
|
if ($feed) {
|
2022-01-03 07:43:22 -05:00
|
|
|
if ($feed->info->detail->user->privateAccount) {
|
|
|
|
http_response_code(400);
|
|
|
|
return 'Private account detected! Not supported';
|
|
|
|
}
|
|
|
|
$latte->render(getView('user'), ['feed' => $feed]);
|
2022-01-01 14:14:57 -05:00
|
|
|
} else {
|
2022-01-03 07:43:22 -05:00
|
|
|
return 'ERROR!';
|
2022-01-01 14:14:57 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-01-03 07:43:22 -05:00
|
|
|
Route::add("/settings", function () use ($proxy_elements) {
|
|
|
|
$latte = getLatte();
|
|
|
|
$latte->render(getView('settings'), ["proxy_elements" => $proxy_elements]);
|
2022-01-02 11:39:22 -05:00
|
|
|
});
|
|
|
|
|
2022-01-03 07:43:22 -05:00
|
|
|
Route::add("/settings", function () use ($proxy_elements) {
|
2022-01-02 11:39:22 -05:00
|
|
|
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');
|
2022-01-03 07:43:22 -05:00
|
|
|
}, 'POST');
|
2022-01-02 11:39:22 -05:00
|
|
|
|
2022-01-03 07:43:22 -05:00
|
|
|
$subdir = getenv('APP_SUBDIR');
|
|
|
|
Route::run($subdir);
|