mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-19 21:03:54 -07:00
Multiple Scrape (#1018)
This commit is contained in:
parent
4a46694f01
commit
3ba3b5a8db
3 changed files with 52 additions and 33 deletions
|
@ -67,7 +67,7 @@ if (!isset($info_hash)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store info hash in hex format
|
// Store info hash in hex format
|
||||||
$info_hash_hex = bin2hex($info_hash);
|
$info_hash_hex = mb_check_encoding($info_hash, 'UTF8') ? $info_hash : bin2hex($info_hash);
|
||||||
|
|
||||||
// Store peer id
|
// Store peer id
|
||||||
$peer_id_sql = rtrim(DB()->escape(htmlCHR($peer_id)), ' ');
|
$peer_id_sql = rtrim(DB()->escape(htmlCHR($peer_id)), ' ');
|
||||||
|
@ -436,9 +436,11 @@ if (!$output) {
|
||||||
'complete' => (int)$seeders,
|
'complete' => (int)$seeders,
|
||||||
'incomplete' => (int)$leechers,
|
'incomplete' => (int)$leechers,
|
||||||
'downloaded' => (int)$client_completed,
|
'downloaded' => (int)$client_completed,
|
||||||
'peers' => $peers,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if (!empty($peers)) {
|
||||||
|
$output['peers'] = $peers;
|
||||||
|
}
|
||||||
if (!empty($peers6)) {
|
if (!empty($peers6)) {
|
||||||
$output['peers6'] = $peers6;
|
$output['peers6'] = $peers6;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,16 +22,14 @@ if (isset($_GET['?info_hash']) && !isset($_GET['info_hash'])) {
|
||||||
$_GET['info_hash'] = $_GET['?info_hash'];
|
$_GET['info_hash'] = $_GET['?info_hash'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$is_bt_v2 = null;
|
|
||||||
$info_hash = isset($_GET['info_hash']) ? (string)$_GET['info_hash'] : null;
|
$info_hash = isset($_GET['info_hash']) ? (string)$_GET['info_hash'] : null;
|
||||||
|
|
||||||
// Verify info_hash
|
// Verify info_hash
|
||||||
if (!isset($info_hash)) {
|
if (!isset($info_hash)) {
|
||||||
msg_die('info_hash was not provided');
|
msg_die('info_hash was not provided');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store info hash in hex format
|
// Store info hash in hex format
|
||||||
$info_hash_hex = bin2hex($info_hash);
|
$info_hash_hex = mb_check_encoding($info_hash, 'UTF8') ? $info_hash : bin2hex($info_hash);
|
||||||
|
|
||||||
// Check info_hash version
|
// Check info_hash version
|
||||||
if (strlen($info_hash) == 32) {
|
if (strlen($info_hash) == 32) {
|
||||||
|
@ -42,37 +40,55 @@ if (strlen($info_hash) == 32) {
|
||||||
msg_die('Invalid info_hash: ' . $info_hash_hex);
|
msg_die('Invalid info_hash: ' . $info_hash_hex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($lp_scrape_info = CACHE('tr_cache')->get(SCRAPE_LIST_PREFIX . $info_hash_hex)) {
|
// Handle multiple hashes
|
||||||
die(\Arokettu\Bencode\Bencode::encode($lp_scrape_info));
|
|
||||||
}
|
|
||||||
|
|
||||||
$info_hash_sql = rtrim(DB()->escape($info_hash), ' ');
|
preg_match_all('/info_hash=([^&]*)/i', $_SERVER["QUERY_STRING"], $info_hash_array);
|
||||||
/**
|
|
||||||
* Поскольку торрент-клиенты в настоящее время обрезают инфо-хэш до 20 символов (независимо от его типа, как известно v1 = 20 символов, а v2 = 32 символа),
|
|
||||||
* то результатов $is_bt_v2 (исходя из длины строки определяем тип инфо-хэша) проверки нам будет мало, именно поэтому происходит поиск v2 хэша, если торрент является v1 (по длине) и если в tor.info_hash столбце нету v1 хэша.
|
|
||||||
*/
|
|
||||||
$info_hash_where = $is_bt_v2 ? "WHERE tor.info_hash_v2 = '$info_hash_sql'" : "WHERE tor.info_hash = '$info_hash_sql' OR tor.info_hash_v2 LIKE '$info_hash_sql%'";
|
|
||||||
|
|
||||||
$row = DB()->fetch_row("
|
$torrents = [];
|
||||||
SELECT tor.complete_count, snap.seeders, snap.leechers
|
$info_hashes = [];
|
||||||
FROM " . BB_BT_TORRENTS . " tor
|
|
||||||
LEFT JOIN " . BB_BT_TRACKER_SNAP . " snap ON (snap.topic_id = tor.topic_id)
|
|
||||||
$info_hash_where
|
|
||||||
LIMIT 1
|
|
||||||
");
|
|
||||||
|
|
||||||
if (!$row) {
|
foreach ($info_hash_array[1] as $hash) {
|
||||||
msg_die('Torrent not registered, info_hash = ' . $info_hash_hex);
|
if ($scrape_cache = CACHE('tr_cache')->get(SCRAPE_LIST_PREFIX . bin2hex(urldecode($hash)))) {
|
||||||
}
|
$torrents['files'][$info_key = array_key_first($scrape_cache)] = $scrape_cache[$info_key];
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$info_hashes[] = '\''. DB()->escape((urldecode($hash))) . '\'';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$output['files'][$info_hash] = [
|
$info_hash_count = count($info_hashes);
|
||||||
'complete' => (int)$row['seeders'],
|
|
||||||
'downloaded' => (int)$row['complete_count'],
|
|
||||||
'incomplete' => (int)$row['leechers'],
|
|
||||||
];
|
|
||||||
|
|
||||||
$peers_list_cached = CACHE('tr_cache')->set(SCRAPE_LIST_PREFIX . $info_hash_hex, $output, SCRAPE_LIST_EXPIRE);
|
if (!empty($info_hash_count)) {
|
||||||
|
|
||||||
echo \Arokettu\Bencode\Bencode::encode($output);
|
if ($info_hash_count > $bb_cfg['max_scrapes']) {
|
||||||
|
$info_hashes = array_slice($info_hashes, 0, $bb_cfg['max_scrapes']);
|
||||||
|
}
|
||||||
|
|
||||||
exit;
|
$info_hashes_sql = 'tor.info_hash' . ' IN ( ' . implode(', ', $info_hashes). ' )';
|
||||||
|
$sql = "
|
||||||
|
SELECT tor.info_hash, tor.complete_count, snap.seeders, snap.leechers
|
||||||
|
FROM " . BB_BT_TORRENTS . " tor
|
||||||
|
LEFT JOIN " . BB_BT_TRACKER_SNAP . " snap ON (snap.topic_id = tor.topic_id)
|
||||||
|
WHERE $info_hashes_sql
|
||||||
|
LIMIT $info_hash_count
|
||||||
|
";
|
||||||
|
|
||||||
|
$rowset = DB()->fetch_rowset($sql);
|
||||||
|
|
||||||
|
if (count($rowset) > 0) {
|
||||||
|
foreach ($rowset as $scrapes) {
|
||||||
|
$torrents['files'][$scrapes['info_hash']] = [
|
||||||
|
'complete' => (int)$scrapes['seeders'],
|
||||||
|
'downloaded' => (int)$scrapes['complete_count'],
|
||||||
|
'incomplete' => (int)$scrapes['leechers']
|
||||||
|
];
|
||||||
|
CACHE('tr_cache')->set(SCRAPE_LIST_PREFIX . bin2hex($scrapes['info_hash']), array_slice($torrents['files'], -1, null, true), SCRAPE_LIST_EXPIRE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($torrents)) {
|
||||||
|
msg_die('Torrent not registered, info_hash = ' . $info_hash_hex);
|
||||||
|
}
|
||||||
|
|
||||||
|
die(\Arokettu\Bencode\Bencode::encode($torrents));
|
||||||
|
|
|
@ -95,7 +95,8 @@ $bb_cfg['gzip_compress'] = false; // compress output
|
||||||
|
|
||||||
// Tracker
|
// Tracker
|
||||||
$bb_cfg['announce_interval'] = 1800; // Announce interval (default: 1800)
|
$bb_cfg['announce_interval'] = 1800; // Announce interval (default: 1800)
|
||||||
$bb_cfg['scrape_interval'] = 60; // Scrape interval (default: 60)
|
$bb_cfg['scrape_interval'] = 100; // Scrape interval (default: 100)
|
||||||
|
$bb_cfg['max_scrapes'] = 20; // Allowed number of info-hashes for simultaneous scraping (default: 20)
|
||||||
$bb_cfg['passkey_key'] = 'uk'; // Passkey key name in GET request
|
$bb_cfg['passkey_key'] = 'uk'; // Passkey key name in GET request
|
||||||
$bb_cfg['ignore_reported_ip'] = false; // Ignore IP reported by client
|
$bb_cfg['ignore_reported_ip'] = false; // Ignore IP reported by client
|
||||||
$bb_cfg['verify_reported_ip'] = true; // Verify IP reported by client against $_SERVER['HTTP_X_FORWARDED_FOR']
|
$bb_cfg['verify_reported_ip'] = true; // Verify IP reported by client against $_SERVER['HTTP_X_FORWARDED_FOR']
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue