video.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. function get_video_results($query, $page=0)
  3. {
  4. global $config;
  5. $url = "https://www.google.$config->google_domain/search?&q=$query&start=$page&hl=$config->google_language&tbm=vid";
  6. $response = request($url);
  7. $xpath = get_xpath($response);
  8. $results = array();
  9. foreach($xpath->query("//div[@id='search']//div[contains(@class, 'g')]") as $result)
  10. {
  11. $url = $xpath->evaluate(".//a/@href", $result)[0];
  12. if ($url == null)
  13. continue;
  14. if (!empty($results)) // filter duplicate results
  15. if (end($results)["url"] == $url->textContent)
  16. continue;
  17. $url = $url->textContent;
  18. $url = privacy_friendly_alternative($url);
  19. $title = $xpath->evaluate(".//h3", $result)[0];
  20. array_push($results,
  21. array (
  22. "title" => htmlspecialchars($title->textContent),
  23. "url" => htmlspecialchars($url),
  24. "base_url" => htmlspecialchars(get_base_url($url))
  25. )
  26. );
  27. }
  28. return $results;
  29. }
  30. function print_video_results($results)
  31. {
  32. echo "<div class=\"text-result-container\">";
  33. foreach($results as $result)
  34. {
  35. $title = $result["title"];
  36. $url = $result["url"];
  37. $base_url = $result["base_url"];
  38. echo "<div class=\"text-result-wrapper\">";
  39. echo "<a href=\"$url\">";
  40. echo "$base_url";
  41. echo "<h2>$title</h2>";
  42. echo "</a>";
  43. echo "</div>";
  44. }
  45. echo "</div>";
  46. }
  47. ?>