replaced brave video search with invidious, fixed the broken json, fixed the broken main tor instance

This commit is contained in:
hnhx 2023-01-27 18:17:57 +01:00
parent c050a09429
commit 8edd1f9d46
13 changed files with 103 additions and 86 deletions

View File

@ -13,7 +13,7 @@
| Clearnet | TOR | I2P | Country |
|-|-|-|-|
| [search.femboy.hu](https://search.femboy.hu/) | [](http://search.femboy2vec5mc3rdvecifqrwzpiaeoyfh4zodppxq4pc2tdvzhm4moqd.onion/) | ❌ | 🇭🇺 HU (OFFICIAL INSTANCE) |
| [search.femboy.hu](https://search.femboy.hu/) | [](http://search.cepyxplublbyw2f4axy4pyztfbxmf63lrt2c7uwv6wl4iixz53czload.onion/) | ❌ | 🇭🇺 HU (OFFICIAL INSTANCE) |
| [lx.vern.cc](https://lx.vern.cc/) | [](http://lx.vernccvbvyi5qhfzyqengccj7lkove6bjot2xhh5kajhwvidqafczrad.onion/) | [](http://vernziqfqvweijfaacmwazohgpdo2bt2ib2jlupt2pwwu27bhgxq.b32.i2p/) | 🇺🇸 US |
| [lx.sesu.cc](https://lx.sesu.cc/) | [](http://lx.swxoebbpeqiiixyhbuh3vbw53pdrmtbiaj2sqveol6kkn5rpapfi4aad.onion/) | [](http://lqbchqljxiwl3bbjt4vqe76luovk5ly6khqhg7mt5qcqfn6e4sbq.b32.i2p/) | 🇨🇱 CL |
| [librex.mikata.ru](https://librex.mikata.ru/) | [](http://f7ssz7l3biu4fugwctfpcx4txg5yq4gqhrt473ledsuc3ivtd3omniid.onion/) | ❌ | 🇺🇸 US |
@ -43,7 +43,7 @@ Huge thanks to Richard Stallman for using LibreX and featuring it on his [websit
### About LibreX
LibreX gives you results from Google, Brave, Qwant, Ahmia and popular torrent sites without spying on you.
LibreX gives you results from Google, Qwant, Ahmia and popular torrent sites without spying on you.
<br>
<br>
If you would like to learn more about LibreX check out the [Wiki](https://github.com/hnhx/librex/wiki).

View File

@ -34,7 +34,7 @@
$results = get_image_results($query_encoded, $page);
break;
case 2:
require "engines/brave/video.php";
require "engines/invidious/video.php";
$results = get_video_results($query_encoded);
break;
case 3:

View File

@ -7,6 +7,9 @@
// Google results will be in this language
"google_language" => "en",
// If you have a local instance you can change this to http://localhost:3000
"invidious_instance_for_video_results" => "https://invidious.namazso.eu",
"disable_bittorent_search" => false,
"bittorent_trackers" => "&tr=http%3A%2F%2Fnyaa.tracker.wf%3A7777%2Fannounce&tr=udp%3A%2F%2Fopen.stealth.si%3A80%2Fannounce&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Fexodus.desync.com%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.torrent.eu.org%3A451%2Fannounce",
@ -49,7 +52,7 @@
// CURLOPT_PROXYTYPE => CURLPROXY_HTTP,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36",
CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36",
CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_PROTOCOLS => CURLPROTO_HTTPS | CURLPROTO_HTTP,

View File

@ -15,8 +15,6 @@
<h2>Monero (XMR):</h2>
<p>41dGQr9EwZBfYBY3fibTtJZYfssfRuzJZDSVDeneoVcgckehK3BiLxAV4FvEVJiVqdiW996zvMxhFB8G8ot9nBFqQ84VkuC</p>
<img src="static/images/xmr.png" alt="xmr qr code" width="150" height="150"/>
<h2>Liberapay</h2>
<a href="https://en.liberapay.com/hnhx/donate" target="_blank">liberapay.com/hnhx</a>
</div>
<?php require "misc/footer.php"; ?>

View File

@ -1,65 +0,0 @@
<?php
function get_video_results($query)
{
global $config;
$url = "https://search.brave.com/videos?q=$query&source=web";
$response = request($url);
$xpath = get_xpath($response);
$results = array();
foreach($xpath->query("//div[@id='results']//div[@class='card']") as $result)
{
$url = $xpath->evaluate(".//a/@href", $result)[0]->textContent;
$title = $xpath->evaluate(".//div/@title", $result)[0]->textContent;
$views = $xpath->evaluate(".//div/@title", $result)[1]->textContent;
$date = $xpath->evaluate(".//div//span", $result)[0]->textContent;
$thumbnail_raw1 = $xpath->evaluate(".//div/@style", $result)[0]->textContent;
$thumbnail_raw2 = explode("url('", $thumbnail_raw1)[1];
$thumbnail = explode("'), url", $thumbnail_raw2)[0];
$url = check_for_privacy_frontend($url);
array_push($results,
array (
"title" => htmlspecialchars($title),
"url" => htmlspecialchars($url),
"base_url" => htmlspecialchars(get_base_url($url)),
"views" => htmlspecialchars($views),
"date" => htmlspecialchars($date),
"thumbnail" => htmlspecialchars($thumbnail)
)
);
}
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"];
$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>$date - $views</span>";
echo "</a>";
echo "</div>";
}
echo "</div>";
}
?>

View File

@ -10,7 +10,12 @@
$domain = $config->google_domain;
$language = isset($_COOKIE["google_language"]) ? htmlspecialchars($_COOKIE["google_language"]) : $config->google_language;
$url = "https://www.google.$domain/search?&q=$query_encoded&start=$page&hl=$language&lr=lang_$language";
$url = "https://www.google.$domain/search?&q=$query_encoded&start=$page";
if (3 > strlen($language))
{
$url .= "&hl=$language&lr=lang_$language";
}
if (isset($_COOKIE["safe_search"]))
{

View File

@ -0,0 +1,70 @@
<?php
function get_video_results($query)
{
global $config;
$instance_url = $config->invidious_instance_for_video_results;
$url = "$instance_url/api/v1/search?q=$query";
$response = request($url);
$json_response = json_decode($response, true);
$results = array();
foreach ($json_response as $response)
{
if ($response["type"] == "video")
{
$title = $response["title"];
$url = $instance_url . "/watch?v=" . $response["videoId"];
$url = check_for_privacy_frontend($url);
$uploader = $response["author"];
$views = $response["viewCount"];
$date = $response["publishedText"];
$thumbnail = $instance_url . "/vi/" . explode("/vi/" ,$response["videoThumbnails"][4]["url"])[1];
array_push($results,
array (
"title" => htmlspecialchars($title),
"url" => htmlspecialchars($url),
"base_url" => htmlspecialchars(get_base_url($url)),
"uploader" => htmlspecialchars($uploader),
"views" => htmlspecialchars($views),
"date" => htmlspecialchars($date),
"thumbnail" => htmlspecialchars($thumbnail)
)
);
}
}
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>";
}
?>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 750 B

View File

@ -4,16 +4,11 @@
require "misc/tools.php";
$url = $_REQUEST["url"];
$requested_root_domain = get_root_domain($url);
$split_url = explode("/", $url);
$base_url = $split_url[2];
$allowed_domains = array("qwant.com", "wikimedia.org", get_root_domain($config->invidious_instance_for_video_results));
$base_url_main_split = explode(".", strrev($base_url));
$base_url_main = strrev($base_url_main_split[1]) . "." . strrev($base_url_main_split[0]);
$allowed_domains = array("qwant.com", "wikimedia.org", "brave.com");
if (in_array($base_url_main, $allowed_domains))
if (in_array($requested_root_domain, $allowed_domains))
{
$image = $url;
$image_src = request($image);

View File

@ -2,7 +2,7 @@
"instances": [
{
"clearnet": "https://search.femboy.hu/",
"tor": "http://librex.2356uhnbpv5nk3bni5bv6jg2cd6lgj664kwx3lhyelstpttpyv4kk2qd.onion/",
"tor": "http://search.cepyxplublbyw2f4axy4pyztfbxmf63lrt2c7uwv6wl4iixz53czload.onion/",
"i2p": null,
"country": "HU"
},
@ -35,7 +35,7 @@
"tor": "http://5yblccekvswxl4n43bn5eg4pr7c4xygvu5lhhdb6ulzmislvahmhitad.onion",
"i2p": null,
"country": "PL"
}
},
{
"clearnet": "https://search.davidovski.xyz/",
"tor": null,

View File

@ -6,6 +6,17 @@
return $base_url;
}
function get_root_domain($url)
{
$split_url = explode("/", $url);
$base_url = $split_url[2];
$base_url_main_split = explode(".", strrev($base_url));
$root_domain = strrev($base_url_main_split[1]) . "." . strrev($base_url_main_split[0]);
return $root_domain;
}
function try_replace_with_frontend($url, $frontend, $original)
{
$config = require "config.php";

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
<ShortName>LibreX</ShortName>
<Description>A privacy respecting meta search engine.</Description>
<Description>Framework and javascript free privacy respecting meta search engine</Description>
<InputEncoding>UTF-8</InputEncoding>
<LongName>LibreX search</LongName>
<Url rel="results" type="text/html" method="get" template="http://localhost/search.php?q={searchTerms}" />
<Url rel="results" type="text/html" method="get" template="http://localhost:80/search.php?q={searchTerms}" />
<Url type="application/opensearchdescription+xml"
rel="self"
template="/opensearch.xml?method=POST" />
template="/opensearch.xml?method=GET" />
</OpenSearchDescription>

View File

@ -89,7 +89,7 @@
break;
case 2:
require "engines/brave/video.php";
require "engines/invidious/video.php";
$results = get_video_results($query_encoded);
print_elapsed_time($start_time);
print_video_results($results);