From 7d8b12ba9dc949bde1305d303088ac957d325cc0 Mon Sep 17 00:00:00 2001 From: lolcat Date: Mon, 8 Jun 2026 00:48:34 -0400 Subject: [PATCH] cleaning up useless shit --- audio/linear.php | 20 ---- audio/sc.php | 224 --------------------------------------------- audio/seekable.php | 20 ---- audio/spotify.php | 214 ------------------------------------------- 4 files changed, 478 deletions(-) delete mode 100644 audio/linear.php delete mode 100644 audio/sc.php delete mode 100644 audio/seekable.php delete mode 100644 audio/spotify.php diff --git a/audio/linear.php b/audio/linear.php deleted file mode 100644 index b6a848f..0000000 --- a/audio/linear.php +++ /dev/null @@ -1,20 +0,0 @@ -stream_linear_audio($_GET["s"]); -}catch(Exception $error){ - - header("X-Error: " . $error->getMessage()); -} diff --git a/audio/sc.php b/audio/sc.php deleted file mode 100644 index 6dfe66e..0000000 --- a/audio/sc.php +++ /dev/null @@ -1,224 +0,0 @@ -proxy = new proxy(); - - if(isset($_GET["u"])){ - - /* - we're now proxying audio - */ - $viewkey = $_GET["u"]; - - if(!isset($_GET["r"])){ - - $this->do404("Ranges(r) are missing"); - } - - $ranges = explode(",", $_GET["r"]); - - // sanitize ranges - foreach($ranges as &$range){ - - if(!is_numeric($range)){ - - $this->do404("Invalid range specified"); - } - - $range = (int)$range; - } - - // sort ranges (just to make sure) - sort($ranges); - - // convert ranges to pairs - $last = -1; - foreach($ranges as &$r){ - - $tmp = $r; - $r = [$last + 1, $r]; - - $last = $tmp; - } - - $browser_headers = getallheaders(); - - // get the requested range from client - $client_range = 0; - foreach($browser_headers as $key => $value){ - - if(strtolower($key) == "range"){ - - preg_match( - '/bytes=([0-9]+)/', - $value, - $client_regex - ); - - if(isset($client_regex[1])){ - - $client_range = (int)$client_regex[1]; - }else{ - - $client_range = 0; - } - break; - } - } - - if( - $client_range < 0 || - $client_range > $ranges[count($ranges) - 1][1] - ){ - - // range is not satisfiable - http_response_code(416); - header("Content-Type: text/plain"); - die(); - } - - $rng = null; - for($i=0; $iproxy->stream_linear_audio( - $viewkey - ); - }catch(Exception $error){ - - $this->do404("Could not read stream"); - } - - die(); - } - - /* - redirect user to correct resource - we need to scrape and store the byte positions in the result URL - */ - if(!isset($_GET["s"])){ - - $this->do404("The URL(s) parameter is missing"); - } - - $viewkey = $_GET["s"]; - - if( - preg_match( - '/soundcloud\.com$/', - parse_url($viewkey, PHP_URL_HOST) - ) === false - ){ - - $this->do404("This endpoint can only be used for soundcloud streams"); - } - - try{ - - $json = $this->proxy->get($viewkey)["body"]; - }catch(Exception $error){ - - $this->do404("Curl error: " . $error->getMessage()); - } - - $json = json_decode($json, true); - - if(!isset($json["url"])){ - - $this->do404("Could not get URL from JSON"); - } - - $viewkey = $json["url"]; - - $m3u8 = $this->proxy->get($viewkey)["body"]; - - $m3u8 = explode("\n", $m3u8); - - $lineout = null; - $streampos_arr = []; - foreach($m3u8 as $line){ - - $line = trim($line); - if($line[0] == "#"){ - - continue; - } - - if($lineout === null){ - $lineout = $line; - } - - preg_match( - '/\/media\/[0-9]+\/([0-9]+)\/([0-9]+)/', - $line, - $matches - ); - - if(isset($matches[0])){ - - $streampos_arr[] = [ - (int)$matches[1], - (int)$matches[2] - ]; - } - } - - if($lineout === null){ - - $this->do404("Could not get stream URL"); - } - - $lineout = - preg_replace( - '/\/media\/([0-9]+)\/[0-9]+\/[0-9]+/', - '/media/$1/0/0', - $lineout - ); - - $streampos = []; - - foreach($streampos_arr as $pos){ - - $streampos[] = $pos[1]; - } - - $streampos = implode(",", $streampos); - - header("Location: /audio/sc?u=" . urlencode($lineout) . "&r=$streampos"); - header("Accept-Ranges: bytes"); - } - - private function do404($error){ - - http_response_code(404); - header("Content-Type: text/plain"); - header("X-Error: $error"); - die(); - } -} diff --git a/audio/seekable.php b/audio/seekable.php deleted file mode 100644 index b6a848f..0000000 --- a/audio/seekable.php +++ /dev/null @@ -1,20 +0,0 @@ -stream_linear_audio($_GET["s"]); -}catch(Exception $error){ - - header("X-Error: " . $error->getMessage()); -} diff --git a/audio/spotify.php b/audio/spotify.php deleted file mode 100644 index dc8fae6..0000000 --- a/audio/spotify.php +++ /dev/null @@ -1,214 +0,0 @@ -fuckhtml = new fuckhtml(); - - if( - !isset($_GET["s"]) || - !preg_match( - '/^(track|episode)\.([A-Za-z0-9]{22})$/', - $_GET["s"], - $matches - ) - ){ - - $this->do404("The track ID(s) parameter is missing or invalid"); - } - - try{ - - if($matches[1] == "episode"){ - - $uri = "show"; - }else{ - - $uri = $matches[1]; - } - - $embed = - $this->get("https://embed.spotify.com/{$uri}/" . $matches[2]); - }catch(Exception $error){ - - $this->do404("Failed to fetch embed data"); - } - - $this->fuckhtml->load($embed); - - $json = - $this->fuckhtml - ->getElementById( - "__NEXT_DATA__", - "script" - ); - - if($json === null){ - - $this->do404("Failed to extract JSON"); - } - - $json = - json_decode($json["innerHTML"], true); - - if($json === null){ - - $this->do404("Failed to decode JSON"); - } - - switch($matches[1]){ - - case "track": - if( - isset( - $json - ["props"] - ["pageProps"] - ["state"] - ["data"] - ["entity"] - ["audioPreview"] - ["url"] - ) - ){ - - header("Content-type: audio/mpeg"); - header( - "Location: /audio/linear?s=" . - urlencode( - $json - ["props"] - ["pageProps"] - ["state"] - ["data"] - ["entity"] - ["audioPreview"] - ["url"] - ) - ); - }else{ - - $this->do404("Could not extract playback URL"); - } - break; - - case "episode": - if( - isset( - $json - ["props"] - ["pageProps"] - ["state"] - ["data"] - ["entity"] - ["id"] - ) - ){ - - try{ - $json = - $this->get( - "https://spclient.wg.spotify.com/soundfinder/v1/unauth/episode/" . - $json - ["props"] - ["pageProps"] - ["state"] - ["data"] - ["entity"] - ["id"] . - "/com.widevine.alpha" - ); - }catch(Exception $error){ - - $this->do404("Failed to fetch audio resource"); - } - - $json = json_decode($json, true); - - if($json === null){ - - $this->do404("Failed to decode audio resource JSON"); - } - - if( - isset($json["passthrough"]) && - $json["passthrough"] == "ALLOWED" && - isset($json["passthroughUrl"]) - ){ - - header( - "Location:" . - "/audio/linear.php?s=" . - urlencode( - str_replace( - "http://", - "https://", - $json["passthroughUrl"] - ) - ) - ); - }else{ - - $this->do404("Failed to find passthroughUrl"); - } - - }else{ - - $this->do404("Failed to find episode ID"); - } - break; - } - } - - private function get($url){ - - $headers = [ - "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: none", - "Sec-Fetch-User: ?1" - ]; - - $curlproc = curl_init(); - - curl_setopt($curlproc, CURLOPT_URL, $url); - - curl_setopt($curlproc, CURLOPT_ENCODING, ""); // default encoding - curl_setopt($curlproc, CURLOPT_HTTPHEADER, $headers); - - curl_setopt($curlproc, CURLOPT_RETURNTRANSFER, true); - curl_setopt($curlproc, CURLOPT_SSL_VERIFYHOST, 2); - curl_setopt($curlproc, CURLOPT_SSL_VERIFYPEER, true); - curl_setopt($curlproc, CURLOPT_CONNECTTIMEOUT, 30); - curl_setopt($curlproc, CURLOPT_TIMEOUT, 30); - - $data = curl_exec($curlproc); - - if(curl_errno($curlproc)){ - throw new Exception(curl_error($curlproc)); - } - - curl_close($curlproc); - return $data; - } - - private function do404($error){ - - http_response_code(404); - header("Content-Type: text/plain"); - header("X-Error: $error"); - die(); - } -}