videos.php 3.9 KB

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