diff --git a/src/SHttp.php b/src/SHttp.php index 10ec289..13ad905 100644 --- a/src/SHttp.php +++ b/src/SHttp.php @@ -2,7 +2,7 @@ namespace Satori; final class SHttp { - public static function getJson(string $url): mixed { + public static function getJson(string $url, bool $pretendToBeFirefox = false): mixed { $curl = curl_init($url); curl_setopt_array($curl, [ CURLOPT_AUTOREFERER => true, @@ -17,16 +17,35 @@ final class SHttp { CURLOPT_REDIR_PROTOCOLS => CURLPROTO_HTTPS, CURLOPT_CONNECTTIMEOUT => 2, CURLOPT_TIMEOUT => 5, - CURLOPT_USERAGENT => sprintf('Satori/%s (+https://fii.moe/satori)', SAT_VERSION), - CURLOPT_HTTPHEADER => ['Accept: application/json'], ]); + + if($pretendToBeFirefox) { + curl_setopt_array($curl, [ + CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0', + CURLOPT_HTTPHEADER => [ + 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8', + 'Accept-Language: en-GB,en;q=0.5', + 'Sec-Fetch-Dest: document', + 'Sec-Fetch-Mode: navigate', + 'Sec-Fetch-Site: none', + 'Sec-Fetch-User: ?1', + 'Upgrade-Insecure-Requests: 1', + ], + ]); + } else { + curl_setopt_array($curl, [ + CURLOPT_USERAGENT => sprintf('Satori/%s (+https://fii.moe/satori)', SAT_VERSION), + CURLOPT_HTTPHEADER => ['Accept: application/json'], + ]); + } + $response = json_decode(curl_exec($curl), true); curl_close($curl); return $response; } - public static function getJsonCached(string $url): mixed { - return SFileCache::for15mins($url, fn() => self::getJson($url)); + public static function getJsonCached(string $url, bool $pretendToBeFirefox = false): mixed { + return SFileCache::for15mins($url, fn() => self::getJson($url, $pretendToBeFirefox)); } } diff --git a/src/Splatoon/Splatoon1/Splatoon1Game.php b/src/Splatoon/Splatoon1/Splatoon1Game.php index 3eaf84f..a2d9ff5 100644 --- a/src/Splatoon/Splatoon1/Splatoon1Game.php +++ b/src/Splatoon/Splatoon1/Splatoon1Game.php @@ -57,7 +57,7 @@ class Splatoon1Game implements ISplatoonGame, ISplatoonHasSchedules { public function createLocale(string $locale): ISplatoonLocale { return new Splatoon1Locale( - SHttp::getJsonCached(sprintf(self::LOCALE_URL, $locale)) + SHttp::getJsonCached(sprintf(self::LOCALE_URL, $locale), true) ); } @@ -94,7 +94,7 @@ class Splatoon1Game implements ISplatoonGame, ISplatoonHasSchedules { private ?array $rawSchedule = null; private function getRawScheduleData(): array { if($this->rawSchedule === null) - $this->rawSchedule = SHttp::getJsonCached(self::SCHED_URL); + $this->rawSchedule = SHttp::getJsonCached(self::SCHED_URL, true); return $this->rawSchedule; }