This commit is contained in:
lolcat 2024-04-21 19:31:56 -04:00
parent 9e18327df6
commit 130358a9e0
16 changed files with 1385 additions and 457 deletions

View file

@ -70,7 +70,7 @@ class sc{
return $data;
}
public function music($get){
public function music($get, $last_attempt = false){
if($get["npt"]){
@ -108,6 +108,7 @@ class sc{
$type = $get["type"];
$proxy = $this->backend->get_ip();
$token = $this->get_token($proxy);
switch($type){
@ -117,12 +118,11 @@ class sc{
"q" => $search,
"variant_ids" => "",
"facet" => "model",
"user_id" => config::SC_USER_ID,
"client_id" => config::SC_CLIENT_TOKEN,
"client_id" => $token,
"limit" => 20,
"offset" => 0,
"linked_partitioning" => 1,
"app_version" => 1696577813,
"app_version" => 1713542117,
"app_locale" => "en"
];
break;
@ -133,12 +133,11 @@ class sc{
"q" => $search,
"variant_ids" => "",
"facet_genre" => "",
"user_id" => config::SC_USER_ID,
"client_id" => config::SC_CLIENT_TOKEN,
"client_id" => $token,
"limit" => 20,
"offset" => 0,
"linked_partitioning" => 1,
"app_version" => 1696577813,
"app_version" => 1713542117,
"app_locale" => "en"
];
break;
@ -149,12 +148,11 @@ class sc{
"q" => $search,
"variant_ids" => "",
"facet" => "place",
"user_id" => config::SC_USER_ID,
"client_id" => config::SC_CLIENT_TOKEN,
"client_id" => $token,
"limit" => 20,
"offset" => 0,
"linked_partitioning" => 1,
"app_version" => 1696577813,
"app_version" => 1713542117,
"app_locale" => "en"
];
break;
@ -165,12 +163,11 @@ class sc{
"q" => $search,
"variant_ids" => "",
"facet" => "genre",
"user_id" => config::SC_USER_ID,
"client_id" => config::SC_CLIENT_TOKEN,
"client_id" => $token,
"limit" => 20,
"offset" => 0,
"linked_partitioning" => 1,
"app_version" => 1696577813,
"app_version" => 1713542117,
"app_locale" => "en"
];
break;
@ -181,12 +178,11 @@ class sc{
"q" => $search,
"variant_ids" => "",
"facet" => "genre",
"user_id" => config::SC_USER_ID,
"client_id" => config::SC_CLIENT_TOKEN,
"client_id" => $token,
"limit" => 20,
"offset" => 0,
"linked_partitioning" => 1,
"app_version" => 1696577813,
"app_version" => 1713542117,
"app_locale" => "en"
];
break;
@ -198,12 +194,11 @@ class sc{
"variant_ids" => "",
"filter.content_tier" => "SUB_HIGH_TIER",
"facet" => "genre",
"user_id" => config::SC_USER_ID,
"client_id" => config::SC_CLIENT_TOKEN,
"client_id" => $token,
"limit" => 20,
"offset" => 0,
"linked_partitioning" => 1,
"app_version" => 1696577813,
"app_version" => 1713542117,
"app_locale" => "en"
];
break;
@ -229,7 +224,14 @@ class sc{
if($json === null){
throw new Exception("Failed to decode JSON. Did the keys set in data/config.php expire?");
if($last_attempt === true){
throw new Exception("Fetched an invalid token (please report!!)");
}
// token might've expired, get a new one and re-try search
get_token($proxy);
return $this->music($get, true);
}
$out = [
@ -352,7 +354,7 @@ class sc{
"endpoint" => "sc",
"url" =>
$item["media"]["transcodings"][0]["url"] .
"?client_id=" . config::SC_CLIENT_TOKEN .
"?client_id=" . $token .
"&track_authorization=" .
$item["track_authorization"]
];
@ -390,6 +392,37 @@ class sc{
return $out;
}
public function get_token($proxy){
$token = apcu_fetch("sc_token");
if($token === false){
$js =
$this->get(
$proxy,
"https://a-v2.sndcdn.com/assets/1-c3e4038d.js",
[]
);
preg_match(
'/client_id=([^"]+)/',
$js,
$token
);
if(!isset($token[1])){
throw new Exception("Failed to get search token");
}
apcu_store("sc_token", $token[1]);
return $token[1];
}
return $token;
}
private function limitstrlen($text){
return