Merge pull request #125 from samip5/configureable_user_agent

Ability to pass custom user agent to the scraper and ignore .git on Docker
This commit is contained in:
Pablo Ferreiro 2023-02-19 11:08:22 +00:00 committed by GitHub
commit bf86e0d36a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 1 deletions

View file

@ -1,5 +1,6 @@
node_modules node_modules
/.env /.env
/.git
/.vscode /.vscode
/vendor /vendor
/cache/latte/* /cache/latte/*

View file

@ -20,3 +20,5 @@
# PROXY_PORT=8080 # PROXY_PORT=8080
# PROXY_USERNAME=username # PROXY_USERNAME=username
# PROXY_PASSWORD=password # PROXY_PASSWORD=password
# USER_AGENT="Mozilla/5.0 (Android 12; Mobile; rv:109.0) Gecko/109.0 Firefox/109.0"

View file

@ -2,6 +2,8 @@
namespace App\Controllers; namespace App\Controllers;
use App\Helpers\Cookies; use App\Helpers\Cookies;
use App\Helpers\Misc;
use TikScraper\Constants\UserAgents as TikScraperUserAgents;
class ProxyController { class ProxyController {
const VALID_TIKTOK_DOMAINS = [ const VALID_TIKTOK_DOMAINS = [
@ -11,7 +13,8 @@ class ProxyController {
static public function stream() { static public function stream() {
self::checkUrl(); self::checkUrl();
$url = $_GET['url']; $url = $_GET['url'];
$streamer = new \TikScraper\Stream(); $config['user_agent'] = Misc::env("USER_AGENT", TikScraperUserAgents::DEFAULT);
$streamer = new \TikScraper\Stream($config);
$streamer->url($url); $streamer->url($url);
} }

View file

@ -7,6 +7,8 @@ use App\Cache\RedisCache;
use App\Constants\CacheMethods; use App\Constants\CacheMethods;
use App\Models\BaseTemplate; use App\Models\BaseTemplate;
use TikScraper\Constants\UserAgents as TikScraperUserAgents;
class Wrappers { class Wrappers {
/** /**
* Setup of Latte template engine * Setup of Latte template engine
@ -162,6 +164,8 @@ class Wrappers {
} }
} }
$options["user_agent"] = Misc::env("USER_AGENT", TikScraperUserAgents::DEFAULT);
return new \TikScraper\Api($options, $cacheEngine); return new \TikScraper\Api($options, $cacheEngine);
} }
} }