video.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. function get_video_results($query)
  3. {
  4. global $config;
  5. $url = "https://search.brave.com/videos?q=$query&source=web";
  6. $response = request($url);
  7. $xpath = get_xpath($response);
  8. $results = array();
  9. foreach($xpath->query("//div[@id='results']//div[@class='card']") as $result)
  10. {
  11. $url = $xpath->evaluate(".//a/@href", $result)[0]->textContent;
  12. $title = $xpath->evaluate(".//div/@title", $result)[0]->textContent;
  13. $views = $xpath->evaluate(".//div/@title", $result)[1]->textContent;
  14. $date = $xpath->evaluate(".//div//span", $result)[0]->textContent;
  15. $thumbnail_raw1 = $xpath->evaluate(".//div/@style", $result)[0]->textContent;
  16. $thumbnail_raw2 = explode("url('", $thumbnail_raw1)[1];
  17. $thumbnail = explode("'), url", $thumbnail_raw2)[0];
  18. $url = check_for_privacy_frontend($url);
  19. array_push($results,
  20. array (
  21. "title" => htmlspecialchars($title),
  22. "url" => htmlspecialchars($url),
  23. "base_url" => htmlspecialchars(get_base_url($url)),
  24. "views" => htmlspecialchars($views),
  25. "date" => htmlspecialchars($date),
  26. "thumbnail" => htmlspecialchars($thumbnail)
  27. )
  28. );
  29. }
  30. return $results;
  31. }
  32. function print_video_results($results)
  33. {
  34. echo "<div class=\"text-result-container\">";
  35. foreach($results as $result)
  36. {
  37. $title = $result["title"];
  38. $url = $result["url"];
  39. $base_url = $result["base_url"];
  40. $views = $result["views"];
  41. $date = $result["date"];
  42. $thumbnail = $result["thumbnail"];
  43. echo "<div class=\"text-result-wrapper\">";
  44. echo "<a href=\"$url\">";
  45. echo "$base_url";
  46. echo "<h2>$title</h2>";
  47. echo "<img class=\"video-img\" src=\"image_proxy.php?url=$thumbnail\">";
  48. echo "<br>";
  49. echo "<span>$date - $views</span>";
  50. echo "</a>";
  51. echo "</div>";
  52. }
  53. echo "</div>";
  54. }
  55. ?>