bump scraper

This commit is contained in:
Pablo Ferreiro 2023-01-26 17:20:38 +01:00
parent 32d49954f9
commit 7d2f6e8fd6
No known key found for this signature in database
GPG key ID: 41FBCE65B779FA24
3 changed files with 38 additions and 37 deletions

View file

@ -8,35 +8,6 @@ class ProxyController {
"tiktokcdn.com", "tiktokcdn-us.com", "tiktok.com"
];
static private function isValidDomain(string $url) {
$host = parse_url($url, PHP_URL_HOST);
$host_split = explode('.', $host);
$host_count = count($host_split);
if ($host_count === 2) {
// Using no watermark
return in_array($host_split[0] . '.' . $host_split[1], self::VALID_TIKTOK_DOMAINS);
} elseif ($host_count === 3) {
return in_array($host_split[1] . '.' . $host_split[2], self::VALID_TIKTOK_DOMAINS);
}
return false;
}
static private function checkUrl() {
if (!isset($_GET['url'])) {
die('You need to send a URL');
}
if (!filter_var($_GET['url'], FILTER_VALIDATE_URL) || !self::isValidDomain($_GET['url'])) {
die('Not a valid URL');
}
}
static private function getFilename(string $id, string $user): string {
$filename = 'tiktok-video-' . $id . '-' . $user;
return $filename;
}
static public function stream() {
self::checkUrl();
$url = $_GET['url'];
@ -59,4 +30,34 @@ class ProxyController {
// Running
$downloader->url($url, $filename, $watermark);
}
static private function isValidDomain(string $url): bool {
$valid = false;
$host = parse_url($url, PHP_URL_HOST);
$host_split = explode('.', $host);
$host_count = count($host_split);
if ($host_count === 2) {
// Using no watermark
$valid = in_array($host_split[0] . '.' . $host_split[1], self::VALID_TIKTOK_DOMAINS);
} elseif ($host_count === 3) {
$valid = in_array($host_split[1] . '.' . $host_split[2], self::VALID_TIKTOK_DOMAINS);
}
return $valid;
}
static private function checkUrl(): void {
if (!isset($_GET['url'])) {
die('You need to send a URL');
}
if (!filter_var($_GET['url'], FILTER_VALIDATE_URL) || !self::isValidDomain($_GET['url'])) {
die('Not a valid URL');
}
}
static private function getFilename(string $id, string $user): string {
$filename = 'tiktok-video-' . $id . '-' . $user;
return $filename;
}
}