Browse Source

Redirect to random instance if google is ratelimiting

gospodin 1 year ago
parent
commit
7559bc8101
1 changed files with 6 additions and 0 deletions
  1. 6 0
      engines/google/text.php

+ 6 - 0
engines/google/text.php

@@ -114,6 +114,12 @@
         }
 
         $xpath = get_xpath(curl_multi_getcontent($google_ch));
+        if (curl_getinfo($google_ch)['http_code'] == '302') {                                                                                               
+                $instances_json = json_decode(file_get_contents("instances.json"), true);                                                                               
+                $instances = array_map(fn($n) => $n['clearnet'], array_filter($instances_json['instances'], fn($n) => !is_null($n['clearnet'])));                           
+                header("Location: " . $instances[array_rand($instances)] . "search.php?q=$query");
+                die();                                                                                   
+        }
 
         foreach($xpath->query("//div[@id='search']//div[contains(@class, 'g')]") as $result)
         {