music.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. /*
  3. Initialize random shit
  4. */
  5. include "data/config.php";
  6. include "lib/frontend.php";
  7. $frontend = new frontend();
  8. [$scraper, $filters] = $frontend->getscraperfilters("music");
  9. $get = $frontend->parsegetfilters($_GET, $filters);
  10. /*
  11. Captcha
  12. */
  13. include "lib/bot_protection.php";
  14. new bot_protection($frontend, $get, $filters, "music", true);
  15. $payload = [
  16. "timetaken" => microtime(true),
  17. "class" => "",
  18. "right-left" => "",
  19. "right-right" => "",
  20. "left" => ""
  21. ];
  22. try{
  23. $results = $scraper->music($get);
  24. }catch(Exception $error){
  25. $frontend->drawscrapererror($error->getMessage(), $get, "music", $payload["timetaken"]);
  26. }
  27. $categories = [
  28. "song" => "",
  29. "author" => "",
  30. "playlist" => "",
  31. "album" => "",
  32. "podcast" => "",
  33. "user" => ""
  34. ];
  35. /*
  36. Set the main container
  37. */
  38. $main = null;
  39. if(count($results["song"]) !== 0){
  40. $main = "song";
  41. }elseif(count($results["album"]) !== 0){
  42. $main = "album";
  43. }elseif(count($results["playlist"]) !== 0){
  44. $main = "playlist";
  45. }elseif(count($results["podcast"]) !== 0){
  46. $main = "podcast";
  47. }elseif(count($results["author"]) !== 0){
  48. $main = "author";
  49. }elseif(count($results["user"]) !== 0){
  50. $main = "user";
  51. }else{
  52. // No results found!
  53. echo
  54. $frontend->drawerror(
  55. "Nobody here but us chickens!",
  56. 'Have you tried:' .
  57. '<ul>' .
  58. '<li>Using a different scraper</li>' .
  59. '<li>Using fewer keywords</li>' .
  60. '<li>Defining broader filters (Is NSFW turned off?)</li>' .
  61. '</ul>' .
  62. '</div>'
  63. );
  64. die();
  65. }
  66. /*
  67. Generate list of songs
  68. */
  69. foreach($categories as $name => $data){
  70. foreach($results[$name] as $item){
  71. $greentext = [];
  72. if(
  73. isset($item["date"]) &&
  74. $item["date"] !== null
  75. ){
  76. $greentext[] = date("jS M y @ g:ia", $item["date"]);
  77. }
  78. if(
  79. isset($item["views"]) &&
  80. $item["views"] !== null
  81. ){
  82. $views = number_format($item["views"]) . " views";
  83. $greentext[] = $views;
  84. }
  85. if(
  86. isset($item["followers"]) &&
  87. $item["followers"] !== null
  88. ){
  89. $greentext[] = number_format($item["followers"]) . " followers";
  90. }
  91. if(
  92. isset($item["author"]["name"]) &&
  93. $item["author"]["name"] !== null
  94. ){
  95. $greentext[] = $item["author"]["name"];
  96. }
  97. $greentext = implode(" • ", $greentext);
  98. if(
  99. isset($item["duration"]) &&
  100. $item["duration"] !== null
  101. ){
  102. $duration = $frontend->s_to_timestamp($item["duration"]);
  103. }else{
  104. $duration = null;
  105. }
  106. $tabindex = $name == $main ? true : false;
  107. $customhtml = null;
  108. if(
  109. (
  110. $name == "song" ||
  111. $name == "podcast"
  112. ) &&
  113. $item["stream"]["endpoint"] !== null
  114. ){
  115. $customhtml =
  116. '<audio src="/audio/' . $item["stream"]["endpoint"] . '?s=' . urlencode($item["stream"]["url"]) . '" controls autostart="false" preload="none">';
  117. }
  118. $categories[$name] .= $frontend->drawtextresult($item, $greentext, $duration, $get["s"], $tabindex, $customhtml);
  119. }
  120. }
  121. $payload["left"] = $categories[$main];
  122. // dont re-draw the category
  123. unset($categories[$main]);
  124. /*
  125. Populate right handside
  126. */
  127. $i = 1;
  128. foreach($categories as $name => $value){
  129. if($value == ""){
  130. continue;
  131. }
  132. if($i % 2 === 1){
  133. $write = "right-left";
  134. }else{
  135. $write = "right-right";
  136. }
  137. $payload[$write] .=
  138. '<div class="answer-wrapper">' .
  139. '<input id="answer' . $i . '" class="spoiler" type="checkbox">' .
  140. '<div class="answer">' .
  141. '<div class="answer-title">' .
  142. '<a class="answer-title" href="?s=' . urlencode($get["s"]);
  143. $payload[$write] .=
  144. '&type=' . $name . '"><h2>' . ucfirst($name) . 's</h2></a>';
  145. $payload[$write] .=
  146. '</div>' .
  147. $categories[$name] .
  148. '</div>' .
  149. '<label class="spoiler-button" for="answer' . $i . '"></label></div>';
  150. $i++;
  151. }
  152. if($i !== 1){
  153. $payload["class"] = " has-answer";
  154. }
  155. if($results["npt"] !== null){
  156. $payload["left"] .=
  157. '<a href="' . $frontend->htmlnextpage($get, $results["npt"], "music") . '" class="nextpage">Next page &gt;</a>';
  158. }
  159. echo $frontend->load("search.html", $payload);