Download services, scraper bump

This commit is contained in:
Pablo Ferreiro 2022-09-25 19:53:00 +02:00
parent c076ba65a6
commit 7aa869f567
No known key found for this signature in database
GPG key ID: 41FBCE65B779FA24
27 changed files with 191 additions and 73 deletions

View file

@ -1,6 +1,9 @@
<?php
namespace App\Controllers;
use App\Helpers\Cookies;
use TikScraper\Helpers\Converter;
class ProxyController {
const VALID_TIKTOK_DOMAINS = [
"tiktokcdn.com", "tiktokcdn-us.com", "tiktok.com"
@ -30,11 +33,9 @@ class ProxyController {
}
static private function getFileName(): string {
$filename = 'tiktok-video';
if (isset($_GET['user'])) {
$filename .= '-' . $_GET['user'] . '-' . $_GET['id'];
}
static private function getFilename(string $url, string $user): string {
$id = Converter::urlToId($url);
$filename = 'tiktok-video-' . $id . '-' . $user;
return $filename;
}
@ -46,18 +47,17 @@ class ProxyController {
}
static public function download() {
$downloader = new \TikScraper\Download();
self::checkUrl();
$method = Cookies::downloader();
$downloader = new \TikScraper\Download($method);
// Params
$watermark = isset($_GET['watermark']);
if ($watermark) {
self::checkUrl();
$filename = self::getFileName();
$downloader->url($_GET['url'], $filename, true);
} else {
if (!isset($_GET['id'])) {
die('You need to send an ID!');
}
$filename = self::getFileName();
$downloader->url($_GET['id'], $filename, false);
}
$url = $_GET['url'];
$user = $_GET['user'] ?? '';
// Filename
$filename = self::getFilename($url, $user);
// Running
$downloader->url($_GET['url'], $filename, $watermark);
}
}