video.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. function get_video_results($query)
  3. {
  4. global $config;
  5. // Randomly choose a instance
  6. $results = array();
  7. $num = array_rand($config->instances);
  8. $instance = $config->instances[$num];
  9. $url = "https://$instance/api.php";
  10. // API POST field
  11. $post_string = "q=$query&t=2";
  12. // alternative frontends
  13. // fuck the cookie abuse in API
  14. if (!isset($_COOKIE["disable_frontends"]))
  15. {
  16. if (isset($_COOKIE["invidious"]))
  17. $cookies=array("invidious"=>$_COOKIE["invidious"]);
  18. else if (!empty($config->frontends["invidious"]["instance_url"]))
  19. $cookies=array("invidious"=>$config->frontends["invidious"]["instance_url"]);
  20. else
  21. $cookies=array("invidious"=>null);
  22. }
  23. else
  24. $cookies=array("disable_frontends"=>$_COOKIE["disable_frontends"]);
  25. $api_ch = curl_init($url);
  26. curl_setopt_array($api_ch, $config->curl_settings);
  27. curl_setopt($api_ch, CURLOPT_CUSTOMREQUEST, "POST");
  28. curl_setopt($api_ch, CURLOPT_COOKIE, http_build_query($cookies, '', ';'));
  29. curl_setopt($api_ch, CURLOPT_POSTFIELDS, $post_string);
  30. $results = json_decode(curl_exec($api_ch),true);
  31. if($results == null) $results = "$instance is broken";
  32. return $results;
  33. }
  34. function print_video_results($results)
  35. {
  36. echo "<div class=\"text-result-container\">";
  37. foreach($results as $result)
  38. {
  39. $title = $result["title"];
  40. $url = $result["url"];
  41. $base_url = $result["base_url"];
  42. $uploader = $result["uploader"];
  43. $views = $result["views"];
  44. $date = $result["date"];
  45. $thumbnail = $result["thumbnail"];
  46. echo "<div class=\"text-result-wrapper\">";
  47. echo "<a href=\"$url\">";
  48. echo "$base_url";
  49. echo "<h2>$title</h2>";
  50. echo "<img class=\"video-img\" src=\"image_proxy.php?url=$thumbnail\">";
  51. echo "<br>";
  52. echo "<span>$uploader - $date - $views views</span>";
  53. echo "</a>";
  54. echo "</div>";
  55. }
  56. echo "</div>";
  57. }
  58. ?>