diff options
author | lolcat <will@lolcat.ca> | 2023-09-03 22:41:44 -0400 |
---|---|---|
committer | lolcat <will@lolcat.ca> | 2023-09-03 22:41:44 -0400 |
commit | c8ab934b108c83a391583ea8ae7f717c9753926e (patch) | |
tree | 35f23c328249b3259de5e2a60c23a314c84f62f4 /music.php | |
parent | cfd44438aea9740e0a2c34487424c87126862cc9 (diff) |
soundcloud lolllllll
Diffstat (limited to 'music.php')
-rw-r--r-- | music.php | 224 |
1 files changed, 224 insertions, 0 deletions
diff --git a/music.php b/music.php new file mode 100644 index 0000000..61078b9 --- /dev/null +++ b/music.php @@ -0,0 +1,224 @@ +<?php + +/* + Initialize random shit +*/ +include "lib/frontend.php"; +$frontend = new frontend(); + +[$scraper, $filters] = $frontend->getscraperfilters("music"); + +$get = $frontend->parsegetfilters($_GET, $filters); + +$frontend->loadheader( + $get, + $filters, + "music" +); + +$payload = [ + "class" => "", + "right-left" => "", + "right-right" => "", + "left" => "" +]; + +try{ + $results = $scraper->music($get); + +}catch(Exception $error){ + + echo + $frontend->drawerror( + "Shit", + 'This scraper returned an error:' . + '<div class="code">' . htmlspecialchars($error->getMessage()) . '</div>' . + 'Things you can try:' . + '<ul>' . + '<li>Use a different scraper</li>' . + '<li>Remove keywords that could cause errors</li>' . + '<li>Use another 4get instance</li>' . + '</ul><br>' . + 'If the error persists, please <a href="/about">contact the administrator</a>.' + ); + die(); +} + +$categories = [ + "song" => "", + "author" => "", + "playlist" => "" +]; + +/* + Set the main container +*/ +$main = null; + +if(count($results["song"]) !== 0){ + + $main = "song"; + +}elseif(count($results["author"]) !== 0){ + + $main = "author"; + +}elseif(count($results["playlist"]) !== 0){ + + $main = "playlist"; + +}else{ + + // No results found! + echo + $frontend->drawerror( + "Nobody here but us chickens!", + 'Have you tried:' . + '<ul>' . + '<li>Using a different scraper</li>' . + '<li>Using fewer keywords</li>' . + '<li>Defining broader filters (Is NSFW turned off?)</li>' . + '</ul>' . + '</div>' + ); + die(); +} + +/* + Generate list of songs +*/ +foreach($categories as $name => $data){ + + foreach($results[$name] as $item){ + + $greentext = []; + + if( + isset($item["date"]) && + $item["date"] !== null + ){ + + $greentext[] = date("jS M y @ g:ia", $item["date"]); + } + + if( + isset($item["views"]) && + $item["views"] !== null + ){ + + $views = number_format($item["views"]) . " views"; + $greentext[] = $views; + } + + if( + isset($item["followers"]) && + $item["followers"] !== null + ){ + + $greentext[] = number_format($item["followers"]) . " followers"; + } + + if( + isset($item["author"]["name"]) && + $item["author"]["name"] !== null + ){ + + $greentext[] = $item["author"]["name"]; + } + + $greentext = implode(" • ", $greentext); + + if( + isset($item["duration"]) && + $item["duration"] !== null + ){ + + $duration = $frontend->s_to_timestamp($item["duration"]); + }else{ + + $duration = null; + } + + $tabindex = $name == $main ? true : false; + + $customhtml = null; + + if( + $name == "song" && + $item["stream"]["endpoint"] !== null + ){ + + $customhtml = + '<audio src="' . $item["stream"]["endpoint"] . '?s=' . urlencode($item["stream"]["url"]) . '" controls autostart="false" preload="none">'; + } + + $categories[$name] .= $frontend->drawtextresult($item, $greentext, $duration, $get["s"], $tabindex, $customhtml); + } +} + +$payload["left"] = $categories[$main]; + +// dont re-draw the category +unset($categories[$main]); + +/* + Populate right handside +*/ + +$i = 1; +foreach($categories as $name => $value){ + + if($value == ""){ + + continue; + } + + if($i % 2 === 1){ + + $write = "right-left"; + }else{ + + $write = "right-right"; + } + + $payload[$write] .= + '<div class="answer-wrapper">' . + '<input id="answer' . $i . '" class="spoiler" type="checkbox">' . + '<div class="answer">' . + '<div class="answer-title">' . + '<a class="answer-title" href="?s=' . urlencode($get["s"]); + + switch($name){ + + case "playlist": + $payload[$write] .= + '&type=playlist"><h2>Playlists</h2></a>'; + break; + + case "author": + $payload[$write] .= + '&type=people"><h2>Authors</h2></a>'; + break; + } + + $payload[$write] .= + '</div>' . + $categories[$name] . + '</div>' . + '<label class="spoiler-button" for="answer' . $i . '"></label></div>'; + + $i++; +} + +if($i !== 1){ + + $payload["class"] = " has-answer"; +} + +if($results["npt"] !== null){ + + $payload["left"] .= + '<a href="' . $frontend->htmlnextpage($get, $results["npt"], "music") . '" class="nextpage">Next page ></a>'; +} + +echo $frontend->load("search.html", $payload); |