1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- function get_video_results($query)
- {
- global $config;
- // Randomly choose a instance
- $results = array();
- $num = array_rand($config->instances);
- $instance = $config->instances[$num];
- $url = "https://$instance/api.php";
- // API POST field
- $post_string = "q=$query&t=2";
- // alternative frontends
- // fuck the cookie abuse in API
- if (!isset($_COOKIE["disable_frontends"]))
- {
- if (isset($_COOKIE["invidious"]))
- $cookies=array("invidious"=>$_COOKIE["invidious"]);
- else if (!empty($config->frontends["invidious"]["instance_url"]))
- $cookies=array("invidious"=>$config->frontends["invidious"]["instance_url"]);
- else
- $cookies=array("invidious"=>null);
- }
- else
- $cookies=array("disable_frontends"=>$_COOKIE["disable_frontends"]);
- $api_ch = curl_init($url);
- curl_setopt_array($api_ch, $config->curl_settings);
- curl_setopt($api_ch, CURLOPT_CUSTOMREQUEST, "POST");
- curl_setopt($api_ch, CURLOPT_COOKIE, http_build_query($cookies, '', ';'));
- curl_setopt($api_ch, CURLOPT_POSTFIELDS, $post_string);
- $results = json_decode(curl_exec($api_ch),true);
- if($results == null) $results = "$instance is broken";
- return $results;
- }
- function print_video_results($results)
- {
- echo "<div class=\"text-result-container\">";
- foreach($results as $result)
- {
- $title = $result["title"];
- $url = $result["url"];
- $base_url = $result["base_url"];
- $uploader = $result["uploader"];
- $views = $result["views"];
- $date = $result["date"];
- $thumbnail = $result["thumbnail"];
- echo "<div class=\"text-result-wrapper\">";
- echo "<a href=\"$url\">";
- echo "$base_url";
- echo "<h2>$title</h2>";
- echo "<img class=\"video-img\" src=\"image_proxy.php?url=$thumbnail\">";
- echo "<br>";
- echo "<span>$uploader - $date - $views views</span>";
- echo "</a>";
- echo "</div>";
- }
- echo "</div>";
- }
- ?>
|