From 8edd1f9d46e1df3a80bd290785e7ae7999fc14ba Mon Sep 17 00:00:00 2001 From: hnhx Date: Fri, 27 Jan 2023 18:17:57 +0100 Subject: [PATCH] replaced brave video search with invidious, fixed the broken json, fixed the broken main tor instance --- README.md | 4 +-- api.php | 2 +- config.php.example | 5 ++- donate.php | 2 -- engines/brave/video.php | 65 --------------------------------- engines/google/text.php | 7 +++- engines/invidious/video.php | 70 ++++++++++++++++++++++++++++++++++++ favicon.ico | Bin 1659 -> 750 bytes image_proxy.php | 11 ++---- instances.json | 4 +-- misc/tools.php | 11 ++++++ opensearch.xml.example | 6 ++-- search.php | 2 +- 13 files changed, 103 insertions(+), 86 deletions(-) delete mode 100644 engines/brave/video.php create mode 100644 engines/invidious/video.php diff --git a/README.md b/README.md index 9fcbb6d..1a8e5d3 100644 --- a/README.md +++ b/README.md @@ -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.

If you would like to learn more about LibreX check out the [Wiki](https://github.com/hnhx/librex/wiki). diff --git a/api.php b/api.php index 81338f4..9938333 100644 --- a/api.php +++ b/api.php @@ -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: diff --git a/config.php.example b/config.php.example index b49f788..7075547 100644 --- a/config.php.example +++ b/config.php.example @@ -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, diff --git a/donate.php b/donate.php index 3a23b9e..6e2915e 100644 --- a/donate.php +++ b/donate.php @@ -15,8 +15,6 @@

Monero (XMR):

41dGQr9EwZBfYBY3fibTtJZYfssfRuzJZDSVDeneoVcgckehK3BiLxAV4FvEVJiVqdiW996zvMxhFB8G8ot9nBFqQ84VkuC

xmr qr code -

Liberapay

- liberapay.com/hnhx diff --git a/engines/brave/video.php b/engines/brave/video.php deleted file mode 100644 index f86523f..0000000 --- a/engines/brave/video.php +++ /dev/null @@ -1,65 +0,0 @@ -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 "
"; - - 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 ""; - } - - echo "
"; - } -?> diff --git a/engines/google/text.php b/engines/google/text.php index b406b32..d3520a9 100644 --- a/engines/google/text.php +++ b/engines/google/text.php @@ -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"])) { diff --git a/engines/invidious/video.php b/engines/invidious/video.php new file mode 100644 index 0000000..2c0b731 --- /dev/null +++ b/engines/invidious/video.php @@ -0,0 +1,70 @@ +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 "
"; + + 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 ""; + } + + echo "
"; + } +?> diff --git a/favicon.ico b/favicon.ico index f1412a917d356f28acf9a48fad0e5c4346027502..c0231ea514b3565093b7b77c9a07bb18f28fe79c 100644 GIT binary patch literal 750 zcmVmVq#$f{=uzh*ks-_)-W3y`Wf$v=?P3>=nJ0EJO-x-CWI$f^J4VXT12I z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{N`QK(6D>0Nz$a)aM9e zqLqkwovwWd*re$D2Zk@FH!P^hm(q4b%31PV;2l+@BmKpl;Ee{}RKWWggk37U$h?6C zIOi5Zd2GmP2POzZ?vcLO4op_0K2t2)%$!NPktwKJws``06!<4(4FT3mUn~M9DQ4fQXn}$6E-z-pjsyC1FC7ZML6jdyy;YOCei<4|{RxaRIaX0xyyPn-VprfVsdg z-CX7aPdD1;{=T*s$xS88HV*>{imTYCwO7QAP334Sk^tS7oB*tD`ZrEy{RtXim%Z|* z0nOblrGYiBy#a5zPxvvqcGSY=qC#fYO$ zV-hJ}0KQY$vm{K5G{AJK-H^zYs818Du%R#qR0Xi(zq9x zrLcAj!K)<{9d;Ac4#TPsmU`Lh$N_X6?=m0-gqL6^g=BVP!t5w%5|Ath_A0C?Am>L4 zVA}C&3i;moiq*!mjY;!|QlHt7G~0pM6mJCxV43T9*G2}QfER#U71nk`h;?WB+`{p- zmlW18V1wJ{on7$&UB{aQJf*M>1I-PIc)l;smr}NXa&zfAe3qu2oTylU8OOVT-~eP? zvD&aL+dS0QHky((*+PQ-r@~$!P#0haJiuKoUbTcZz{Lvtt$a>wDOX#TZ5}8TB*F=J z3|Q-?iVLs<9-v{61g0vi{X(#0;=*`&zb6umr8^bQXe6y}>XcD201F4dmnoKN9l+y_ z3G>f#w`m1qX*2MWrLsqd&TJw z2J% diff --git a/image_proxy.php b/image_proxy.php index 4f0a8d4..e0004b4 100644 --- a/image_proxy.php +++ b/image_proxy.php @@ -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); diff --git a/instances.json b/instances.json index e7b18e9..6badd79 100644 --- a/instances.json +++ b/instances.json @@ -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, diff --git a/misc/tools.php b/misc/tools.php index bafb063..0e002c9 100644 --- a/misc/tools.php +++ b/misc/tools.php @@ -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"; diff --git a/opensearch.xml.example b/opensearch.xml.example index fac6052..5297550 100644 --- a/opensearch.xml.example +++ b/opensearch.xml.example @@ -1,11 +1,11 @@ LibreX - A privacy respecting meta search engine. + Framework and javascript free privacy respecting meta search engine UTF-8 LibreX search - + + template="/opensearch.xml?method=GET" /> diff --git a/search.php b/search.php index 33c7659..3bd3e48 100644 --- a/search.php +++ b/search.php @@ -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);