cloudfront ratelimit handler

fd155b192e

soundcloud token expiry fix

800cde93cf
This commit is contained in:
FbIN Support 2025-12-14 20:19:53 +05:30
commit 9dcc131c46

View file

@ -135,6 +135,8 @@ class sc{
$type = $get["type"];
$proxy = $this->backend->get_ip();
// token is not tied to an IP address
$token = $this->get_token($proxy);
switch($type){
@ -247,17 +249,34 @@ class sc{
fclose($handle);
*/
$this->fuckhtml->load($json);
// detect for cloudfront error
$title =
$this->fuckhtml
->getElementsByTagName(
"title"
);
if(
count($title) !== 0 &&
str_contains($title[0]["innerHTML"], "The request could not be satisfied")
){
throw new Exception("Ratelimited by Cloudfront, add some working proxies");
}
$json = json_decode($json, true);
if($json === null){
if($last_attempt === true){
throw new Exception("Fetched an invalid token (please report!!)");
throw new Exception("Fetched an invalid token");
}
// token might've expired, get a new one and re-try search
$this->get_token($proxy);
$token = $this->get_token($proxy, true);
return $this->music($get, true);
}
@ -422,11 +441,14 @@ class sc{
return $out;
}
public function get_token($proxy){
public function get_token($proxy, $force_refresh = false){
$token = apcu_fetch("sc_token");
if($token !== false){
if(
$token !== false &&
$force_refresh === false
){
return $token;
}
@ -509,4 +531,4 @@ class sc{
2
)[0];
}
}
}