Skip to content

Commit

Permalink
replaced brave video search with invidious, fixed the broken json, fi…
Browse files Browse the repository at this point in the history
…xed the broken main tor instance
  • Loading branch information
hnhx committed Jan 27, 2023
1 parent c050a09 commit 8edd1f9
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 86 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion config.php.example
Original file line number Diff line number Diff line change
Expand Up @@ -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",

Expand Down Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions donate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"; ?>
65 changes: 0 additions & 65 deletions engines/brave/video.php

This file was deleted.

7 changes: 6 additions & 1 deletion engines/google/text.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ function get_text_results($query, $page)
$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"]))
{
Expand Down
70 changes: 70 additions & 0 deletions engines/invidious/video.php
Original file line number Diff line number Diff line change
@@ -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 modified favicon.ico
Binary file not shown.
11 changes: 3 additions & 8 deletions image_proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions instances.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"instances": [
{
"clearnet": "https://search.femboy.hu/",
"tor": "http://librex.2356uhnbpv5nk3bni5bv6jg2cd6lgj664kwx3lhyelstpttpyv4kk2qd.onion/",
"tor": "http://search.cepyxplublbyw2f4axy4pyztfbxmf63lrt2c7uwv6wl4iixz53czload.onion/",
"i2p": null,
"country": "HU"
},
Expand Down Expand Up @@ -35,7 +35,7 @@
"tor": "http://5yblccekvswxl4n43bn5eg4pr7c4xygvu5lhhdb6ulzmislvahmhitad.onion",
"i2p": null,
"country": "PL"
}
},
{
"clearnet": "https://search.davidovski.xyz/",
"tor": null,
Expand Down
11 changes: 11 additions & 0 deletions misc/tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ function get_base_url($url)
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";
Expand Down
6 changes: 3 additions & 3 deletions opensearch.xml.example
Original file line number Diff line number Diff line change
@@ -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>
2 changes: 1 addition & 1 deletion search.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8edd1f9

Please sign in to comment.