summaryrefslogtreecommitdiff
path: root/scraper/sc.php
diff options
context:
space:
mode:
Diffstat (limited to 'scraper/sc.php')
-rw-r--r--scraper/sc.php75
1 files changed, 54 insertions, 21 deletions
diff --git a/scraper/sc.php b/scraper/sc.php
index 23742f1..e2e7385 100644
--- a/scraper/sc.php
+++ b/scraper/sc.php
@@ -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