aboutsummaryrefslogtreecommitdiffstats
path: root/scraper
diff options
context:
space:
mode:
authorlolcat <will@lolcat.ca>2026-01-25 03:44:48 -0500
committerlolcat <will@lolcat.ca>2026-01-25 03:44:48 -0500
commit1991206de44f644c44471fcb137993f96446365c (patch)
tree9677331a998d603f2262eca17170e3fb6fd16382 /scraper
parent92eb6ab14d8c9141a54fedbb7b895c616bf393d6 (diff)
fix soundcloud token, again
Diffstat (limited to 'scraper')
-rw-r--r--scraper/sc.php77
1 files changed, 36 insertions, 41 deletions
diff --git a/scraper/sc.php b/scraper/sc.php
index 3475c9a..9b94524 100644
--- a/scraper/sc.php
+++ b/scraper/sc.php
@@ -151,7 +151,7 @@ class sc{
"limit" => 20,
"offset" => 0,
"linked_partitioning" => 1,
- "app_version" => 1713542117,
+ "app_version" => 1769170554,
"app_locale" => "en"
];
break;
@@ -166,7 +166,7 @@ class sc{
"limit" => 20,
"offset" => 0,
"linked_partitioning" => 1,
- "app_version" => 1713542117,
+ "app_version" => 1769170554,
"app_locale" => "en"
];
break;
@@ -181,7 +181,7 @@ class sc{
"limit" => 20,
"offset" => 0,
"linked_partitioning" => 1,
- "app_version" => 1713542117,
+ "app_version" => 1769170554,
"app_locale" => "en"
];
break;
@@ -196,7 +196,7 @@ class sc{
"limit" => 20,
"offset" => 0,
"linked_partitioning" => 1,
- "app_version" => 1713542117,
+ "app_version" => 1769170554,
"app_locale" => "en"
];
break;
@@ -211,7 +211,7 @@ class sc{
"limit" => 20,
"offset" => 0,
"linked_partitioning" => 1,
- "app_version" => 1713542117,
+ "app_version" => 1769170554,
"app_locale" => "en"
];
break;
@@ -227,7 +227,7 @@ class sc{
"limit" => 20,
"offset" => 0,
"linked_partitioning" => 1,
- "app_version" => 1713542117,
+ "app_version" => 1769170554,
"app_locale" => "en"
];
break;
@@ -458,7 +458,7 @@ class sc{
return $token;
}
- // search through all javascript components on the main page
+ // get token from main page
try{
$html =
$this->get(
@@ -474,49 +474,44 @@ class sc{
$this->fuckhtml->load($html);
- $scripts =
- $this->fuckhtml
- ->getElementsByTagName(
- "script"
+ $json =
+ preg_split(
+ '/window.__sc_hydration ?= ?/',
+ $html
);
- foreach($scripts as $script){
-
- if(
- !isset($script["attributes"]["src"]) ||
- strpos($script["attributes"]["src"], "sndcdn.com") === false
- ){
-
- continue;
- }
-
- try{
- $js =
- $this->get(
- $proxy,
- $script["attributes"]["src"],
- []
- );
- }catch(Exception $error){
-
- throw new Exception("Failed to fetch search token");
- }
+ if(!isset($json[1])){
- preg_match(
- '/client_id=([^"]+)/',
- $js,
- $token
+ throw new Exception("Failed to find JSON containing token");
+ }
+
+ $json =
+ json_decode(
+ $this->fuckhtml
+ ->extract_json(
+ $json[1]
+ ),
+ true
);
+
+ if($json === null){
- if(isset($token[1])){
+ throw new Exception("Failed to decode JSON containing token");
+ }
+
+ foreach($json as $item){
+
+ if(
+ isset($item["hydratable"]) &&
+ isset($item["data"]["id"])
+ ){
- apcu_store("sc_token", $token[1]);
- return $token[1];
- break;
+ apcu_store("sc_token", $item["data"]["id"]);
+ return $item["data"]["id"];
}
}
- throw new Exception("Did not find a Soundcloud token in the Javascript blobs");
+ throw new Exception("Failed to find a valid token");
}
private function limitstrlen($text){
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage