diff --git a/README.md b/README.md index c7dcb67..34cef15 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ All you need is a webserver (e.g.: nginx) and PHP, and you are good to go. # API Example API request: `.../api.php?q=gentoo&p=2&type=0`
-Where `q` is the keyword, `p` is the result page (the first page is `0`) and `type` is the search type (`0`=text, `1`=image, `2`=video) +Where `q` is the keyword, `p` is the result page (the first page is `0`) and `type` is the search type (`0`=text, `1`=image, `2`=video, `3`=torrent)

JSON result: + In case of text search: @@ -52,6 +52,12 @@ JSON result: + `title`: Title of the result video + `url`: Full URL of the video + `base_url`: The base URL of the result (e.g.: http://youtube.com/watch -> http://youtube.com/) ++ In case of torrent search: + + `hash`: Hash of the torrent + + `name`: Name of the torrent + + `seeders`: The amount of seeders + + `leechers`: The amount of leechers + + `magnet`: The magnet link
The API also supports both GET and POST requests diff --git a/api.php b/api.php index c6378a2..908b4b9 100644 --- a/api.php +++ b/api.php @@ -1,6 +1,5 @@ "disabled"); + else + { + require "engines/bittorrent/thepiratebay.php"; + $results = get_thepiratebay_results($query_encoded); + } + break; + default: + require "engines/google/text.php"; + $results = get_text_results($query_encoded, $page); + break; + } header('Content-Type: application/json'); echo json_encode($results, JSON_PRETTY_PRINT); diff --git a/config.php b/config.php index 89bad39..2023258 100755 --- a/config.php +++ b/config.php @@ -8,9 +8,8 @@ // Results will be in this language $config_google_language = "en"; - // Maxmium size of the cache - $config_cache_size = 1024 * 1024 * 1024; - + // Disable BitTorrent search + $config_disable_bittorent_search = false; /* youtube.com results will be replaced with the given invidious instance diff --git a/donate.php b/donate.php new file mode 100644 index 0000000..33c1642 --- /dev/null +++ b/donate.php @@ -0,0 +1,13 @@ + + + + + + + \ No newline at end of file diff --git a/donate.xhtml b/donate.xhtml deleted file mode 100644 index 4c978d3..0000000 --- a/donate.xhtml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - LibreX - Donate ❤️ - - - - - - - - - - - - - \ No newline at end of file diff --git a/engines/bittorrent.php b/engines/bittorrent/thepiratebay.php similarity index 50% rename from engines/bittorrent.php rename to engines/bittorrent/thepiratebay.php index 168641f..d9a4735 100644 --- a/engines/bittorrent.php +++ b/engines/bittorrent/thepiratebay.php @@ -1,20 +1,16 @@ "; + + foreach($results as $result) + { + $hash = $result["hash"]; + $name = $result["name"]; + $seeders = $result["seeders"]; + $leechers = $result["leechers"]; + $magnet = $result["magnet"]; + + echo "
"; + echo ""; + echo "$hash"; + echo "

$name

"; + echo "
"; + echo "SE: $seeders - LE: $leechers"; + echo "
"; + } + + echo ""; + } ?> \ No newline at end of file diff --git a/engines/google.php b/engines/google.php deleted file mode 100644 index 629f37f..0000000 --- a/engines/google.php +++ /dev/null @@ -1,45 +0,0 @@ -"; - echo "Google rejected the request! :C"; - echo "

"; - die(); - } - - $htmlDom = new DOMDocument; - @$htmlDom->loadHTML($response); - $xpath = new DOMXPath($htmlDom); - - switch ($type) - { - case 0: - return text_results($xpath); - case 1: - return image_results($xpath); - case 2: - return video_results($xpath); - default: - return text_results($xpath); - } - } -?> \ No newline at end of file diff --git a/results/google/image.php b/engines/google/image.php similarity index 59% rename from results/google/image.php rename to engines/google/image.php index a78bd61..135da9b 100644 --- a/results/google/image.php +++ b/engines/google/image.php @@ -1,7 +1,12 @@ "; + + foreach($results as $result) + { + $src = $result["base64"]; + $alt = $result["alt"]; + + echo ""; + echo ""; + echo ""; + } + + echo ""; + } ?> \ No newline at end of file diff --git a/results/google/text.php b/engines/google/text.php similarity index 59% rename from results/google/text.php rename to engines/google/text.php index 354b37d..391dfd7 100644 --- a/results/google/text.php +++ b/engines/google/text.php @@ -1,9 +1,13 @@ "; + foreach($results as $result) + { + $title = $result["title"]; + $url = $result["url"]; + $base_url = $result["base_url"]; + $description = $result["description"]; + + echo "
"; + echo ""; + echo "$base_url"; + echo "

$title

"; + echo "
"; + echo "$description"; + echo "
"; + } + echo ""; + } ?> \ No newline at end of file diff --git a/results/google/video.php b/engines/google/video.php similarity index 56% rename from results/google/video.php rename to engines/google/video.php index 82af046..725339e 100644 --- a/results/google/video.php +++ b/engines/google/video.php @@ -1,8 +1,12 @@ "; + + foreach($results as $result) + { + $title = $result["title"]; + $url = $result["url"]; + $base_url = $result["base_url"]; + + echo "
"; + echo ""; + echo "$base_url"; + echo "

$title

"; + echo "
"; + echo "
"; + } + + echo ""; + } ?> \ No newline at end of file diff --git a/engines/special.php b/engines/special.php deleted file mode 100644 index a126e8d..0000000 --- a/engines/special.php +++ /dev/null @@ -1,23 +0,0 @@ - count(explode(" ", $query))) // long queries usually wont return a wiki result thats why this check exists - { - require_once "results/special/wikipedia.php"; - wikipedia_results($query_lower); - return; - } - } -?> \ No newline at end of file diff --git a/results/special/currency.php b/engines/special/currency.php similarity index 84% rename from results/special/currency.php rename to engines/special/currency.php index c10f58d..6dde2f1 100644 --- a/results/special/currency.php +++ b/engines/special/currency.php @@ -1,7 +1,8 @@ "; diff --git a/index.php b/index.php new file mode 100644 index 0000000..ff1fc05 --- /dev/null +++ b/index.php @@ -0,0 +1,17 @@ + + + + +
+

LibreX

+ + + + +
+ + +
+
+ + \ No newline at end of file diff --git a/index.xhtml b/index.xhtml deleted file mode 100644 index 7ca99b6..0000000 --- a/index.xhtml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - LibreX - - - - - - - - -
-

LibreX

- - - - -
- - -
-
- - - - \ No newline at end of file diff --git a/misc/tools.php b/misc/tools.php index b85d080..954e972 100644 --- a/misc/tools.php +++ b/misc/tools.php @@ -6,102 +6,33 @@ return $base_url; } - - function print_text_results($results) + function get_xpath($response) { - global $query , $page; + $htmlDom = new DOMDocument; + @$htmlDom->loadHTML($response); + $xpath = new DOMXPath($htmlDom); - if ($page == 0) - check_for_special_search($query); - - echo "
"; - foreach($results as $result) - { - $title = $result["title"]; - $url = $result["url"]; - $base_url = $result["base_url"]; - $description = $result["description"]; - - echo "
"; - echo ""; - echo "$base_url"; - echo "

$title

"; - echo "
"; - echo "$description"; - echo "
"; - } - echo "
"; + return $xpath; } - function print_image_results($results) + function request($url) { - echo "
"; + require "config.php"; - foreach($results as $result) - { - $src = $result["base64"]; - $alt = $result["alt"]; + $ch = curl_init($url); + curl_setopt_array($ch, $config_curl_settings); + $response = curl_exec($ch); - echo ""; - echo ""; - echo ""; - } - - echo "
"; + return $response; } - function print_video_results($results) - { - echo "
"; - - foreach($results as $result) - { - $title = $result["title"]; - $url = $result["url"]; - $base_url = $result["base_url"]; - - echo "
"; - echo ""; - echo "$base_url"; - echo "

$title

"; - echo "
"; - echo "
"; - } - - echo "
"; - } - - function print_bittorrent_results($results) - { - echo "
"; - - foreach($results as $result) - { - $hash = $result["hash"]; - $name = $result["name"]; - $seeders = $result["seeders"]; - $leechers = $result["leechers"]; - $magnet = $result["magnet"]; - - echo "
"; - echo ""; - echo "$hash"; - echo "

$name

"; - echo "
"; - echo "SE: $seeders - LE: $leechers"; - echo "
"; - } - - echo "
"; - } - - function print_next_page_button($page, $button_val, $q, $type) + function print_next_page_button($text, $page, $query, $type) { echo "
"; echo ""; - echo ""; + echo ""; echo ""; - echo ""; + echo ""; echo "
"; } ?> \ No newline at end of file diff --git a/search.php b/search.php index ee5f58e..ea92522 100644 --- a/search.php +++ b/search.php @@ -1,19 +1,10 @@ - - - - <?php echo $_REQUEST["q"]; ?> - LibreX - - - - - - - - + + <?php echo $_REQUEST["q"]; ?> - LibreX +
- +
- - - - + + + +

count(explode(" ", $query))) // long queries usually wont return a wiki result thats why this check exists + { + require "engines/special/wikipedia.php"; + wikipedia_results($query_lower); + return; + } + } $page = isset($_REQUEST["p"]) ? (int) $_REQUEST["p"] : 0; $type = isset($_REQUEST["type"]) ? (int) $_REQUEST["type"] : 0; + + $query_encoded = urlencode($query); - $start_time = microtime(true); - $results = $type != 3 ? get_google_results($query, $page, $type) : get_bittorrent_results($query); - $end_time = number_format(microtime(true) - $start_time, 2, '.', ''); - - echo "

Fetched the results in $end_time seconds

"; - switch ($type) { case 0: + require "engines/google/text.php"; + $results = get_text_results($query_encoded, $page); + if ($page == 0) + check_for_special_search($query); print_text_results($results); break; + case 1: + require "engines/google/image.php"; + $results = get_image_results($query_encoded); print_image_results($results); break; + case 2: + require "engines/google/video.php"; + $results = get_video_results($query_encoded, $page); print_video_results($results); break; + case 3: - print_bittorrent_results($results); + if ($config_disable_bittorent_search) + echo "

The host disabled this feature! :C

"; + else + { + require "engines/bittorrent/thepiratebay.php"; + $results = get_thepiratebay_results($query_encoded); + print_thepiratebay_results($results); + } + break; + default: + require "engines/google/text.php"; + $results = get_text_results($query_encoded, $page); print_text_results($results); break; } - if ($type != 1 && $type != 3 ) + + if ($type == 0 || $type == 2 ) { echo "
"; if ($page != 0) { - print_next_page_button(0, "<<", $query, $type); - print_next_page_button($page - 10, "<", $query, $type); + print_next_page_button("<<", 0, $query, $type); + print_next_page_button("<", $page - 10, $query, $type); } for ($i=$page / 10; $page / 10 + 10 > $i; $i++) - { - $page_input = $i * 10; - $page_button = $i + 1; - - print_next_page_button($page_input, $page_button, $query, $type); - } + print_next_page_button($i + 1, $i * 10, $query, $type); - print_next_page_button($page + 10, ">", $query, $type); + print_next_page_button(">", $page + 10, $query, $type); echo "
"; } ?> - - - \ No newline at end of file + \ No newline at end of file diff --git a/static/footer.html b/static/footer.html new file mode 100644 index 0000000..5751d60 --- /dev/null +++ b/static/footer.html @@ -0,0 +1,8 @@ + + + \ No newline at end of file diff --git a/static/header.html b/static/header.html new file mode 100644 index 0000000..a7c277d --- /dev/null +++ b/static/header.html @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/static/image_result.png b/static/images/image_result.png similarity index 100% rename from static/image_result.png rename to static/images/image_result.png diff --git a/static/librex.png b/static/images/librex.png similarity index 100% rename from static/librex.png rename to static/images/librex.png diff --git a/static/text_result.png b/static/images/text_result.png similarity index 100% rename from static/text_result.png rename to static/images/text_result.png diff --git a/static/torrent_result.png b/static/images/torrent_result.png similarity index 100% rename from static/torrent_result.png rename to static/images/torrent_result.png diff --git a/static/video_result.png b/static/images/video_result.png similarity index 100% rename from static/video_result.png rename to static/images/video_result.png diff --git a/static/xmr.png b/static/images/xmr.png similarity index 100% rename from static/xmr.png rename to static/images/xmr.png