video.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. function get_video_results($query)
  3. {
  4. global $config;
  5. $instance_url = $config->invidious_instance_for_video_results;
  6. $url = "$instance_url/api/v1/search?q=$query";
  7. $response = request($url);
  8. $json_response = json_decode($response, true);
  9. $results = array();
  10. foreach ($json_response as $response)
  11. {
  12. if ($response["type"] == "video")
  13. {
  14. $title = $response["title"];
  15. $url = "https://youtube.com/watch?v=" . $response["videoId"];
  16. $url = check_for_privacy_frontend($url);
  17. $uploader = $response["author"];
  18. $views = $response["viewCount"];
  19. $date = $response["publishedText"];
  20. $thumbnail = $instance_url . "/vi/" . explode("/vi/" ,$response["videoThumbnails"][4]["url"])[1];
  21. array_push($results,
  22. array (
  23. "title" => htmlspecialchars($title),
  24. "url" => htmlspecialchars($url),
  25. "base_url" => htmlspecialchars(get_base_url($url)),
  26. "uploader" => htmlspecialchars($uploader),
  27. "views" => htmlspecialchars($views),
  28. "date" => htmlspecialchars($date),
  29. "thumbnail" => htmlspecialchars($thumbnail)
  30. )
  31. );
  32. }
  33. }
  34. return $results;
  35. }
  36. function print_video_results($results)
  37. {
  38. echo "<div class=\"text-result-container\">";
  39. foreach($results as $result)
  40. {
  41. $title = $result["title"];
  42. $url = $result["url"];
  43. $base_url = $result["base_url"];
  44. $uploader = $result["uploader"];
  45. $views = $result["views"];
  46. $date = $result["date"];
  47. $thumbnail = $result["thumbnail"];
  48. echo "<div class=\"text-result-wrapper\">";
  49. echo "<a href=\"$url\">";
  50. echo "$base_url";
  51. echo "<h2>$title</h2>";
  52. echo "<img class=\"video-img\" src=\"image_proxy.php?url=$thumbnail\">";
  53. echo "<br>";
  54. echo "<span>$uploader - $date - $views views</span>";
  55. echo "</a>";
  56. echo "</div>";
  57. }
  58. echo "</div>";
  59. }
  60. ?>