From d1611c7d8ac1462b4c83bfd726e0a58245be3f0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B8nstantine=20Kovalensky?= <45331093+kovalensky@users.noreply.github.com> Date: Sun, 5 Nov 2023 09:31:27 +0400 Subject: [PATCH] Small improvements to scraping (#1042) --- bt/includes/init_tr.php | 6 ++++-- bt/scrape.php | 17 ++++------------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/bt/includes/init_tr.php b/bt/includes/init_tr.php index e1dbc83f3..2e88694d3 100644 --- a/bt/includes/init_tr.php +++ b/bt/includes/init_tr.php @@ -51,7 +51,7 @@ function drop_fast_announce($lp_info, $lp_cached_peers = []) function msg_die($msg) { $output = \Arokettu\Bencode\Bencode::encode([ - 'min interval' => (int)1800, + 'interval' => (int)1800, 'failure reason' => (string)$msg, ]); @@ -62,7 +62,6 @@ function dummy_exit($interval = 1800, $cache_dict = []) { $output = [ 'interval' => (int)$interval, - 'min interval' => (int)$interval, 'peers' => (string)DUMMY_PEER, ]; @@ -71,6 +70,9 @@ function dummy_exit($interval = 1800, $cache_dict = []) $output['incomplete'] = $cache_dict['incomplete']; $output['downloaded'] = $cache_dict['downloaded']; $output['warning message'] = 'Next statistics update in: ' . (floor($interval / 60) % 60) . ' minutes'; + } + + if (isset($cache_dict['peers6'])) { $output['peers'] = $cache_dict['peers']; } diff --git a/bt/scrape.php b/bt/scrape.php index 563835afb..1d4f38b25 100644 --- a/bt/scrape.php +++ b/bt/scrape.php @@ -31,15 +31,6 @@ if (!isset($info_hash)) { // Store info hash in hex format $info_hash_hex = mb_check_encoding($info_hash, 'UTF8') ? $info_hash : bin2hex($info_hash); -// Check info_hash version -if (strlen($info_hash) == 32) { - $is_bt_v2 = true; -} elseif (strlen($info_hash) == 20) { - $is_bt_v2 = false; -} else { - msg_die('Invalid info_hash: ' . $info_hash_hex); -} - // Handle multiple hashes preg_match_all('/info_hash=([^&]*)/i', $_SERVER['QUERY_STRING'], $info_hash_array); @@ -51,11 +42,11 @@ foreach ($info_hash_array[1] as $hash) { $decoded_hash = urldecode($hash); - if ($scrape_cache = CACHE('tr_cache')->get(SCRAPE_LIST_PREFIX . bin2hex(substr($hash, 0, 20)))) { + if ($scrape_cache = CACHE('tr_cache')->get(SCRAPE_LIST_PREFIX . bin2hex($decoded_hash)) { $torrents['files'][$info_key = array_key_first($scrape_cache)] = $scrape_cache[$info_key]; } else{ - $info_hashes[] = '\''. DB()->escape(($decoded_hash)) . '\''; + $info_hashes[] = DB()->escape(($decoded_hash)); } } @@ -67,8 +58,8 @@ if (!empty($info_hash_count)) { $info_hashes = array_slice($info_hashes, 0, $bb_cfg['max_scrapes']); } - $info_hashes_sql = implode(', ', $info_hashes); - $info_hash_where = $is_bt_v2 ? "tor.info_hash_v2 IN ($info_hashes_sql)" : "tor.info_hash IN ($info_hashes_sql) OR SUBSTRING(tor.info_hash_v2, 1, 20) IN ($info_hashes_sql)"; + $info_hashes_sql = implode('\', \'', $info_hashes); + $info_hash_where = "tor.info_hash IN ('$info_hashes_sql') OR SUBSTRING(tor.info_hash_v2, 1, 20) IN ('$info_hashes_sql')"; $sql = " SELECT tor.info_hash, tor.info_hash_v2, tor.complete_count, snap.seeders, snap.leechers