LibreY- privacy respecting meta search engine |
git clone git://git.acid.vegas/LibreY.git |
Log | Files | Refs | Archive | README | LICENSE |
video.php (2827B)
1 <?php 2 class VideoSearch extends EngineRequest { 3 public function get_request_url() { 4 $this->instance_url = $this->opts->invidious_instance_for_video_results; 5 $query = urlencode($this->query); 6 return "$this->instance_url/api/v1/search?q=$query"; 7 } 8 9 public function parse_results($response) { 10 $results = array(); 11 $json_response = json_decode($response, true); 12 13 foreach ($json_response as $response) { 14 if ($response["type"] == "video") { 15 $title = $response["title"]; 16 $url = "https://youtube.com/watch?v=" . $response["videoId"]; 17 $uploader = $response["author"]; 18 $views = $response["viewCount"]; 19 $date = $response["publishedText"]; 20 $thumbnail = $this->instance_url . "/vi/" . explode("/vi/" ,$response["videoThumbnails"][4]["url"])[1]; 21 22 array_push($results, 23 array ( 24 "title" => htmlspecialchars($title), 25 "url" => htmlspecialchars($url), 26 // base_url is to be removed in the future, see #47 27 "base_url" => htmlspecialchars(get_base_url($url)), 28 "uploader" => htmlspecialchars($uploader), 29 "views" => htmlspecialchars($views), 30 "date" => htmlspecialchars($date), 31 "thumbnail" => htmlspecialchars($thumbnail) 32 ) 33 ); 34 } 35 } 36 37 return $results; 38 } 39 40 public static function print_results($results, $opts) { 41 echo "<div class=\"text-result-container\">"; 42 43 foreach($results as $result) { 44 $title = $result["title"]; 45 $url = $result["url"]; 46 $url = check_for_privacy_frontend($url, $opts); 47 $base_url = get_base_url($url); 48 $uploader = $result["uploader"]; 49 $views = $result["views"]; 50 $date = $result["date"]; 51 $thumbnail = $result["thumbnail"]; 52 53 echo "<div class=\"text-result-wrapper\">"; 54 echo "<a href=\"$url\">"; 55 echo "$base_url"; 56 echo "<h2>$title</h2>"; 57 echo "<img class=\"video-img\" src=\"image_proxy.php?url=$thumbnail\">"; 58 echo "<br>"; 59 echo "<span>$uploader - $date - $views views</span>"; 60 echo "</a>"; 61 echo "</div>"; 62 } 63 64 echo "</div>"; 65 } 66 } 67 ?>