I realize uTorrent is querying this now and then, but uTorrent relies on announcement. This keeps peer counts - scraping - always available and active.
I implemented according to spec. Ported for TTv3.
Upload to root as scrape.php
Add to .htaccess
Let me know if any issues. Try a info hash in the browser
somesite.com/scrape.php?info_hash=xxx
You should see bencoded output. If you do, everything is working as expected.
It will output stats for the clients for unlimited info hashes. Clients usually query one, spec allows for as many as needed.
?info_hash=xxx (default, clients use one per transfers)
Allows:
?info_hash=xxx&info_hash=xxx&info_hash=xxx (and so on)
I implemented according to spec. Ported for TTv3.
Upload to root as scrape.php
Add to .htaccess
RewriteRule ^scrape?$ /scrape.php?%{QUERY_STRING} [NC,L]
<?php
// BEP-48: Tracker Protocol Extension: Scrape
// https://www.bittorrent.org/beps/bep_0048.html
require_once("backend/functions.php");
require_once("backend/BEncode.php");
dbconn();
const MIN_REQ_INTERVAL = 30;
$data = array();
header('Content-Type: text/plain');
if (isset($_GET['info_hash']) && strlen($_GET['info_hash']) > 0) {
if (preg_match_all('/([a-f0-9]{40})/', trim($_SERVER['QUERY_STRING']), $reqhash, PREG_PATTERN_ORDER)) {
foreach ($reqhash[0] as $info_hash) {
$res = SQL_Query_exec("SELECT times_completed, seeders, leechers FROM torrents WHERE info_hash = '$info_hash'");
$comp_res = mysqli_fetch_assoc($res);
$stats = array(
$info_hash => array(
'complete' => intval($comp_res['seeders']),
'downloaded' => intval($comp_res['times_completed']),
'incomplete' => intval($comp_res['leechers'])
)
);
array_push($data, $stats);
}
}
if (!empty($data)) {
echo BEncode(array(
'files' => array(
array_merge(...$data) // PHP 5.6+
),
'flags' => array(
'min_request_interval' => MIN_REQ_INTERVAL
)
));
} else {
echo BEncode(array(
'failure reason' => 'Scrape failed'
));
}
}
Let me know if any issues. Try a info hash in the browser
somesite.com/scrape.php?info_hash=xxx
You should see bencoded output. If you do, everything is working as expected.
It will output stats for the clients for unlimited info hashes. Clients usually query one, spec allows for as many as needed.
?info_hash=xxx (default, clients use one per transfers)
Allows:
?info_hash=xxx&info_hash=xxx&info_hash=xxx (and so on)
Last edited by STorrents2020 on 2022-11-18 00:37:49