diff --git a/api.php b/api.php index 908b4b9..74c7eef 100644 --- a/api.php +++ b/api.php @@ -32,8 +32,8 @@ $results = array("error" => "disabled"); else { - require "engines/bittorrent/thepiratebay.php"; - $results = get_thepiratebay_results($query_encoded); + require "engines/bittorrent/merge.php"; + $results = get_merged_torrent_results($query_encoded); } break; default: diff --git a/config.php b/config.php index 2023258..691094a 100755 --- a/config.php +++ b/config.php @@ -11,6 +11,8 @@ // Disable BitTorrent search $config_disable_bittorent_search = false; + $config_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"; + /* youtube.com results will be replaced with the given invidious instance Get online invidious instances from here: https://docs.invidious.io/Invidious-Instances.md diff --git a/engines/bittorrent/merge.php b/engines/bittorrent/merge.php new file mode 100644 index 0000000..16f4007 --- /dev/null +++ b/engines/bittorrent/merge.php @@ -0,0 +1,46 @@ +"; + + foreach($results as $result) + { + $source = $result["source"]; + $name = $result["name"]; + $magnet = $result["magnet"]; + $seeders = $result["seeders"]; + $leechers = $result["leechers"]; + $size = $result["size"]; + + echo "
"; + echo ""; + echo "$source"; + echo "

$name

"; + echo "
"; + echo "SE: $seeders - "; + echo "LE: $leechers - "; + echo "$size"; + echo "
"; + } + + echo ""; + } + +?> \ No newline at end of file diff --git a/engines/bittorrent/nyaa.php b/engines/bittorrent/nyaa.php new file mode 100644 index 0000000..18550da --- /dev/null +++ b/engines/bittorrent/nyaa.php @@ -0,0 +1,40 @@ +query("//tbody/tr") as $result) + { + global $config_bittorent_trackers; + + $name = $xpath->evaluate(".//td[@colspan='2']//a[not(contains(@class, 'comments'))]/@title", $result)[0]->textContent; + $centered = $xpath->evaluate(".//td[@class='text-center']", $result); + $magnet = $xpath->evaluate(".//a[2]/@href", $centered[0])[0]->textContent; + $magnet_without_tracker = explode("&tr=", $magnet)[0]; + $magnet = $magnet_without_tracker . $config_bittorent_trackers; + $size = $centered[1]->textContent; + $seeders = $centered[3]->textContent; + $leechers = $centered[4]->textContent; + + array_push($results, + array ( + "name" => $name, + "seeders" => (int) $seeders, + "leechers" => (int) $leechers, + "magnet" => $magnet, + "size" => $size, + "source" => "nyaa.si" + ) + ); + } + + return $results; + } +?> \ No newline at end of file diff --git a/engines/bittorrent/thepiratebay.php b/engines/bittorrent/thepiratebay.php index d9a4735..bf46866 100644 --- a/engines/bittorrent/thepiratebay.php +++ b/engines/bittorrent/thepiratebay.php @@ -2,8 +2,8 @@ function get_thepiratebay_results($query) { - require "config.php"; - require "misc/tools.php"; + require_once "config.php"; + require_once "misc/tools.php"; $query = urlencode($query); @@ -16,20 +16,24 @@ foreach ($json_response as $response) { - $hash = $response["info_hash"]; - $name = $response["name"]; - $seeders = $response["seeders"]; - $leechers = $response["leechers"]; + global $config_bittorent_trackers; - $magnet = "magnet:?xt=urn:btih:$hash&dn=$name"; + $size = human_filesize($response["size"]); + $hash = $response["info_hash"]; + $name = $response["name"]; + $seeders = (int) $response["seeders"]; + $leechers = (int) $response["leechers"]; + + $magnet = "magnet:?xt=urn:btih:$hash&dn=$name$config_bittorent_trackers"; array_push($results, array ( - "hash" => $hash, + "size" => $size, "name" => $name, "seeders" => $seeders, "leechers" => $leechers, - "magnet" => $magnet + "magnet" => $magnet, + "source" => "thepiratebay.org" ) ); } @@ -37,28 +41,4 @@ return $results; } - - function print_thepiratebay_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 "
"; - } ?> \ No newline at end of file diff --git a/engines/bittorrent/yts.php b/engines/bittorrent/yts.php new file mode 100644 index 0000000..38e4346 --- /dev/null +++ b/engines/bittorrent/yts.php @@ -0,0 +1,52 @@ + $size, + "name" => $name, + "seeders" => $seeders, + "leechers" => $leechers, + "magnet" => $magnet, + "source" => "yts.mx" + ) + ); + + } + } + } + + return $results; + + } +?> \ No newline at end of file diff --git a/misc/tools.php b/misc/tools.php index 954e972..a4bdf9b 100644 --- a/misc/tools.php +++ b/misc/tools.php @@ -26,6 +26,14 @@ return $response; } + function human_filesize($bytes, $dec = 2) + { + $size = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); + $factor = floor((strlen($bytes) - 1) / 3); + + return sprintf("%.{$dec}f ", $bytes / pow(1024, $factor)) . @$size[$factor]; + } + function print_next_page_button($text, $page, $query, $type) { echo "
"; diff --git a/search.php b/search.php index ea92522..42b2d68 100644 --- a/search.php +++ b/search.php @@ -92,9 +92,10 @@ echo "

The host disabled this feature! :C

"; else { - require "engines/bittorrent/thepiratebay.php"; - $results = get_thepiratebay_results($query_encoded); - print_thepiratebay_results($results); + require "engines/bittorrent/merge.php"; + $results = get_merged_torrent_results($query_encoded); + print_merged_torrent_results($results); + break; } break; diff --git a/static/styles.css b/static/styles.css index 76d05c5..b9fa464 100644 --- a/static/styles.css +++ b/static/styles.css @@ -120,6 +120,7 @@ a:hover, .text-result-wrapper h2:hover { .text-result-wrapper { max-width: 500px; + word-wrap: break-word; margin-top: 35px; }