Compare commits
No commits in common. "d3fe37e7b62d825862f7fbfc75affa0ec19b153d" and "b98a39342103816fe260a9c7c9fd4adf058895c8" have entirely different histories.
d3fe37e7b6
...
b98a393421
103
scraper/sc.php
103
scraper/sc.php
|
@ -6,9 +6,6 @@ class sc{
|
||||||
|
|
||||||
include "lib/backend.php";
|
include "lib/backend.php";
|
||||||
$this->backend = new backend("sc");
|
$this->backend = new backend("sc");
|
||||||
|
|
||||||
include "lib/fuckhtml.php";
|
|
||||||
$this->fuckhtml = new fuckhtml();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getfilters($page){
|
public function getfilters($page){
|
||||||
|
@ -28,7 +25,7 @@ class sc{
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function get($proxy, $url, $get = [], $web_req = false){
|
private function get($proxy, $url, $get = []){
|
||||||
|
|
||||||
$curlproc = curl_init();
|
$curlproc = curl_init();
|
||||||
|
|
||||||
|
@ -40,42 +37,19 @@ class sc{
|
||||||
curl_setopt($curlproc, CURLOPT_URL, $url);
|
curl_setopt($curlproc, CURLOPT_URL, $url);
|
||||||
|
|
||||||
curl_setopt($curlproc, CURLOPT_ENCODING, ""); // default encoding
|
curl_setopt($curlproc, CURLOPT_ENCODING, ""); // default encoding
|
||||||
|
curl_setopt($curlproc, CURLOPT_HTTPHEADER,
|
||||||
// use http2
|
["User-Agent: " . config::USER_AGENT,
|
||||||
curl_setopt($curlproc, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
|
"Accept: application/json, text/javascript, */*; q=0.01",
|
||||||
|
"Accept-Language: en-US,en;q=0.5",
|
||||||
if($web_req === false){
|
"Accept-Encoding: gzip",
|
||||||
|
"Referer: https://soundcloud.com/",
|
||||||
curl_setopt($curlproc, CURLOPT_HTTPHEADER,
|
"Origin: https://soundcloud.com",
|
||||||
["User-Agent: " . config::USER_AGENT,
|
"DNT: 1",
|
||||||
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
|
"Connection: keep-alive",
|
||||||
"Accept-Language: en-US,en;q=0.5",
|
"Sec-Fetch-Dest: empty",
|
||||||
"Accept-Encoding: gzip",
|
"Sec-Fetch-Mode: cors",
|
||||||
"Referer: https://soundcloud.com/",
|
"Sec-Fetch-Site: same-site"]
|
||||||
"Origin: https://soundcloud.com",
|
);
|
||||||
"DNT: 1",
|
|
||||||
"Connection: keep-alive",
|
|
||||||
"Sec-Fetch-Dest: empty",
|
|
||||||
"Sec-Fetch-Mode: cors",
|
|
||||||
"Sec-Fetch-Site: same-site"]
|
|
||||||
);
|
|
||||||
}else{
|
|
||||||
|
|
||||||
curl_setopt($curlproc, CURLOPT_HTTPHEADER,
|
|
||||||
["User-Agent: " . config::USER_AGENT,
|
|
||||||
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
|
|
||||||
"Accept-Language: en-US,en;q=0.5",
|
|
||||||
"Accept-Encoding: gzip",
|
|
||||||
"DNT: 1",
|
|
||||||
"Connection: keep-alive",
|
|
||||||
"Upgrade-Insecure-Requests: 1",
|
|
||||||
"Sec-Fetch-Dest: document",
|
|
||||||
"Sec-Fetch-Mode: navigate",
|
|
||||||
"Sec-Fetch-Site: cross-site",
|
|
||||||
"Priority: u=1",
|
|
||||||
"TE: trailers"]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
curl_setopt($curlproc, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($curlproc, CURLOPT_RETURNTRANSFER, true);
|
||||||
curl_setopt($curlproc, CURLOPT_SSL_VERIFYHOST, 2);
|
curl_setopt($curlproc, CURLOPT_SSL_VERIFYHOST, 2);
|
||||||
|
@ -422,47 +396,13 @@ class sc{
|
||||||
|
|
||||||
$token = apcu_fetch("sc_token");
|
$token = apcu_fetch("sc_token");
|
||||||
|
|
||||||
if($token !== false){
|
if($token === false){
|
||||||
|
|
||||||
return $token;
|
|
||||||
}
|
|
||||||
|
|
||||||
// search through all javascript components on the main page
|
|
||||||
try{
|
|
||||||
$html =
|
|
||||||
$this->get(
|
|
||||||
$proxy,
|
|
||||||
"https://soundcloud.com",
|
|
||||||
[]
|
|
||||||
);
|
|
||||||
}catch(Exception $error){
|
|
||||||
|
|
||||||
throw new Exception("Failed to fetch front page");
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->fuckhtml->load($html);
|
|
||||||
|
|
||||||
$scripts =
|
|
||||||
$this->fuckhtml
|
|
||||||
->getElementsByTagName(
|
|
||||||
"script"
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach($scripts as $script){
|
|
||||||
|
|
||||||
if(
|
|
||||||
!isset($script["attributes"]["src"]) ||
|
|
||||||
strpos($script["attributes"]["src"], "sndcdn.com") === false
|
|
||||||
){
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
$js =
|
$js =
|
||||||
$this->get(
|
$this->get(
|
||||||
$proxy,
|
$proxy,
|
||||||
$script["attributes"]["src"],
|
"https://a-v2.sndcdn.com/assets/0-a901c1e0.js",
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
}catch(Exception $error){
|
}catch(Exception $error){
|
||||||
|
@ -476,15 +416,16 @@ class sc{
|
||||||
$token
|
$token
|
||||||
);
|
);
|
||||||
|
|
||||||
if(isset($token[1])){
|
if(!isset($token[1])){
|
||||||
|
|
||||||
apcu_store("sc_token", $token[1]);
|
throw new Exception("Failed to get search token");
|
||||||
return $token[1];
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
apcu_store("sc_token", $token[1]);
|
||||||
|
return $token[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Exception("Did not find a Soundcloud token in the Javascript blobs");
|
return $token;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function limitstrlen($text){
|
private function limitstrlen($text){
|
||||||
|
|
Loading…
Reference in New Issue