Browse Source

added rutor to bittorrent results , added back elapsed time

hnh.mtf 3 years ago
parent
commit
9197e5f967
7 changed files with 82 additions and 12 deletions
  1. 13 8
      config.php
  2. 3 1
      engines/bittorrent/merge.php
  3. 41 0
      engines/bittorrent/rutor.php
  4. 2 1
      engines/google/text.php
  5. 2 1
      engines/google/video.php
  6. 13 0
      misc/tools.php
  7. 8 1
      search.php

+ 13 - 8
config.php

@@ -1,11 +1,11 @@
 <?php
     // This user agent will be used when parsing the results
-    $config_user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.81 Safari/537.36";
+    $config_user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36";
     
     // e.g.: fr -> https://google.fr/
     $config_google_domain = "com";
 
-    // Results will be in this language
+    // Google results will be in this language
     $config_google_language = "en";
 
     $config_disable_bittorent_search = false;
@@ -19,8 +19,10 @@
         Online nitter instances: https://github.com/zedeus/nitter/wiki/Instances
         Online libreddit instances: https://github.com/spikecodes/libreddit
         
-        Set as null or 0 if you don't want to replace results
+        If you don't want to replace YouTube for an example but you want to replace everything else:
+        $config_replace_youtube_with_invidious = null;
     */
+    $config_disable_privacy_friendly_frontends = false; // setting this to true will disable all of them
     $config_replace_youtube_with_invidious = "https://yewtu.be";
     $config_replace_instagram_with_bibliogram = "https://bibliogram.pussthecat.org";
     $config_replace_twitter_with_nitter = "https://nitter.namazso.eu";
@@ -47,11 +49,14 @@
         // CURLOPT_PROXY => "ip:port",
         // CURLOPT_PROXYTYPE => CURLPROXY_HTTP,
         CURLOPT_RETURNTRANSFER => true,
-        CURLOPT_HEADER         => false,
-        CURLOPT_FOLLOWLOCATION => false,
-        CURLOPT_ENCODING       => "",
-        CURLOPT_USERAGENT      => $config_user_agent,
+        CURLOPT_ENCODING => "",
+        CURLOPT_USERAGENT => $config_user_agent,
+        CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
+        CURLOPT_CUSTOMREQUEST => "GET",
         CURLOPT_SSL_VERIFYHOST => false,
-        CURLOPT_VERBOSE        => 1
+        CURLOPT_SSL_VERIFYPEER => false,
+        CURLOPT_SSL_VERIFYSTATUS => false,
+        CURLOPT_VERBOSE => false,
+        CURLOPT_TCP_FASTOPEN => true
     );
 ?>

+ 3 - 1
engines/bittorrent/merge.php

@@ -3,10 +3,12 @@
     function get_merged_torrent_results($query)
     {
         require "engines/bittorrent/thepiratebay.php";
+        require "engines/bittorrent/rutor.php";
         require "engines/bittorrent/nyaa.php";
         require "engines/bittorrent/yts.php";
 
-        $results = array_merge(get_thepiratebay_results($query), 
+        $results = array_merge(get_thepiratebay_results($query),
+                               get_rutor_results($query),
                                get_nyaa_results($query),
                                get_yts_results($query));
 

+ 41 - 0
engines/bittorrent/rutor.php

@@ -0,0 +1,41 @@
+<?php
+    function get_rutor_results($query)
+    {
+        require_once "config.php";
+        require_once "misc/tools.php";
+
+        $url = "http://rutor.info/search/$query";
+        $response = request($url);
+        $xpath = get_xpath($response);
+
+        $results = array();
+
+
+        foreach($xpath->query("//table/tr[@class='gai' or @class='tum']") as $result)
+        {
+
+            global $config_bittorent_trackers;
+
+            $name = $xpath->evaluate(".//td/a", $result)[2]->textContent;
+            $magnet =  $xpath->evaluate(".//td/a/@href", $result)[1]->textContent;
+            $magnet_without_tracker = explode("&tr=", $magnet)[0];
+            $magnet = $magnet_without_tracker . $config_bittorent_trackers;
+            $size = $xpath->evaluate(".//td", $result)[3]->textContent;
+            $seeders = $xpath->evaluate(".//span", $result)[0]->textContent;
+            $leechers = $xpath->evaluate(".//span", $result)[1]->textContent;
+
+            array_push($results, 
+                array (
+                    "name" => $name,
+                    "seeders" => (int) remove_special($seeders),
+                    "leechers" => (int) remove_special($leechers),
+                    "magnet" => $magnet,
+                    "size" => $size,
+                    "source" => "rutor.info"
+                )
+            );
+        }
+
+        return $results;
+    }
+?>

+ 2 - 1
engines/google/text.php

@@ -108,7 +108,8 @@
                
 
             $url = $url->textContent;
-            $url = check_for_privacy_friendly_alternative($url);
+            if (!$config_disable_privacy_friendly_frontends)
+                $url = check_for_privacy_friendly_alternative($url);
             
             $title = $xpath->evaluate(".//h3", $result)[0];
             $description = $xpath->evaluate(".//div[contains(@class, 'VwiC3b')]", $result)[0];

+ 2 - 1
engines/google/video.php

@@ -22,7 +22,8 @@
                     continue;
 
             $url = $url->textContent;
-            $url = check_for_privacy_friendly_alternative($url);
+            if (!$config_disable_privacy_friendly_frontends)
+                $url = check_for_privacy_friendly_alternative($url);
             
             $title = $xpath->evaluate(".//h3", $result)[0];
             

+ 13 - 0
misc/tools.php

@@ -55,6 +55,19 @@
         return sprintf("%.{$dec}f ", $bytes / pow(1024, $factor)) . @$size[$factor];
     }
 
+    function remove_special($string) 
+    {
+        $string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
+     
+        return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
+     }
+
+    function print_elapsed_time($start_time)
+        {
+            $end_time = number_format(microtime(true) - $start_time, 2, '.', '');
+            echo "<p id=\"time\">Fetched the results in $end_time seconds</p>";
+        }
+
     function print_next_page_button($text, $page, $query, $type) 
     {
         echo "<form id=\"page\" action=\"search.php\" target=\"_top\" method=\"post\" enctype=\"multipart/form-data\" autocomplete=\"off\">";

+ 8 - 1
search.php

@@ -1,5 +1,6 @@
 
 <?php require "static/header.html"; ?>
+
 <title> <?php echo $_REQUEST["q"]; ?> - LibreX</title>
 </head>
     <body>
@@ -40,26 +41,30 @@
 
             $page = isset($_REQUEST["p"]) ? (int) $_REQUEST["p"] : 0;
             $type = isset($_REQUEST["type"]) ? (int) $_REQUEST["type"] : 0;
-            
+        
             $query_encoded = urlencode($query);
 
+            $start_time = microtime(true);
             switch ($type)
             {
                 case 0:
                     require "engines/google/text.php";
                     $results = get_text_results($query, $page);
+                    print_elapsed_time($start_time);
                     print_text_results($results);
                     break;
 
                 case 1:
                     require "engines/google/image.php";
                     $results = get_image_results($query_encoded);
+                    print_elapsed_time($start_time);
                     print_image_results($results);
                     break;
 
                 case 2:
                     require "engines/google/video.php";
                     $results = get_video_results($query_encoded, $page);
+                    print_elapsed_time($start_time);
                     print_video_results($results);
                     break;
 
@@ -70,6 +75,7 @@
                     {
                         require "engines/bittorrent/merge.php";
                         $results = get_merged_torrent_results($query_encoded);
+                        print_elapsed_time($start_time);
                         print_merged_torrent_results($results);
                         break;
                     }
@@ -80,6 +86,7 @@
                     require "engines/google/text.php";
                     $results = get_text_results($query_encoded, $page);
                     print_text_results($results);
+                    print_elapsed_time($start_time);
                     break;
             }