add support for cucked urls
This commit is contained in:
1 parent
e03c582f74
commit
ffb1fc00f3
8 files changed
+223
-318
No files matched your search
@@ -1,17 +1,17 @@
|
||||
<?php
|
||||
|
||||
class sc{
|
||||
class brave{
|
||||
|
||||
public function __construct(){
|
||||
|
||||
include "lib/backend.php";
|
||||
$this->backend = new backend("sc");
|
||||
$this->backend = new backend("brave");
|
||||
|
||||
include "lib/fuckhtml.php";
|
||||
$this->fuckhtml = new fuckhtml();
|
||||
}
|
||||
|
||||
private function get($proxy, $url, $get = []){
|
||||
private function get(/*$proxy, */$url, $get = []){
|
||||
|
||||
$curlproc = curl_init();
|
||||
|
||||
@@ -29,7 +29,7 @@ class sc{
|
||||
["User-Agent: " . config::USER_AGENT,
|
||||
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
|
||||
"Accept-Language: en-US,en;q=0.5",
|
||||
"Accept-Encoding: gzip",
|
||||
"Accept-Encoding: gzip, deflate, br, zstd",
|
||||
"DNT: 1",
|
||||
"Sec-GPC: 1",
|
||||
"Connection: keep-alive",
|
||||
@@ -40,7 +40,8 @@ class sc{
|
||||
"Sec-Fetch-User: ?1",
|
||||
"Priority: u=0, i"];
|
||||
|
||||
$this->backend->assign_proxy($curlproc, $proxy);
|
||||
// i dont think proxies are necessary here...
|
||||
//$this->backend->assign_proxy($curlproc, $proxy);
|
||||
|
||||
curl_setopt($curlproc, CURLOPT_ENCODING, ""); // default encoding
|
||||
curl_setopt($curlproc, CURLOPT_HTTPHEADER, $headers);
|
||||
@@ -61,57 +62,51 @@ class sc{
|
||||
return $data;
|
||||
}
|
||||
|
||||
function resolve($id){
|
||||
function resolve($id, $signature){
|
||||
|
||||
if(
|
||||
!preg_match(
|
||||
'/^(t|p)[0-9]+$/',
|
||||
$id
|
||||
)
|
||||
){
|
||||
$sig_status = $this->backend->hmac_verify(4, "brave,{$id}", $signature);
|
||||
|
||||
if($sig_status["valid"] === false){
|
||||
|
||||
throw new Exception("ID is invalid");
|
||||
throw new Exception("[Signature] " . $sig_status["reason"]);
|
||||
}
|
||||
|
||||
$type = $id[0] == "t" ? "track" : "playlist";
|
||||
$id = substr($id, 1);
|
||||
|
||||
try{
|
||||
$html =
|
||||
$this->get(
|
||||
$this->backend->get_ip(),
|
||||
"https://w.soundcloud.com/player/",
|
||||
[
|
||||
"url" => "http://api.soundcloud.com/{$type}s/{$id}",
|
||||
"show_artwork" => "true"
|
||||
]
|
||||
);
|
||||
}catch(Exception $error){
|
||||
|
||||
throw new Exception("Failed to fetch song embed page");
|
||||
}
|
||||
$html =
|
||||
$this->get(
|
||||
//$this->backend->get_ip(),
|
||||
"https://search.brave.com/go/v1/{$id}",
|
||||
);
|
||||
|
||||
$this->fuckhtml->load($html);
|
||||
|
||||
$link =
|
||||
$a =
|
||||
$this->fuckhtml
|
||||
->getElementsByAttributeValue(
|
||||
"rel",
|
||||
"canonical",
|
||||
"link"
|
||||
->getElementsByClassName(
|
||||
"destination",
|
||||
"a"
|
||||
);
|
||||
|
||||
if(count($link) === 0){
|
||||
if(count($a) === 0){
|
||||
|
||||
throw new Exception("Soundcloud could not resolve the song ID to an URL");
|
||||
throw new Exception("Failed to find link");
|
||||
}
|
||||
|
||||
return
|
||||
$link =
|
||||
$this->fuckhtml
|
||||
->getTextContent(
|
||||
$link[0]
|
||||
["attributes"]
|
||||
["href"]
|
||||
$a[0]["attributes"]["href"]
|
||||
);
|
||||
|
||||
if(
|
||||
preg_match(
|
||||
'/^(https?:|)\/\//',
|
||||
$link
|
||||
)
|
||||
){
|
||||
|
||||
return $link;
|
||||
}
|
||||
|
||||
throw new Exception("Got malformed link: " . $link);
|
||||
}
|
||||
}
|
||||
+8
-1
@@ -62,7 +62,14 @@ class google{
|
||||
return $data;
|
||||
}
|
||||
|
||||
function resolve($id){
|
||||
function resolve($id, $signature){
|
||||
|
||||
$sig_status = $this->backend->hmac_verify(4, "google,{$id}", $signature);
|
||||
|
||||
if($sig_status["valid"] === false){
|
||||
|
||||
throw new Exception("[Signature] " . $sig_status["reason"]);
|
||||
}
|
||||
|
||||
$html =
|
||||
$this->get(
|
||||
|
||||
Reference in new issue
Block a user