Login
Username: Password:
Remember me

[Sign Up] / [Recover Password]

Theme / Language

Popular
New Torrents
new name
Size: 18.40 MB
Most active
new name
S: 74 L: 3
New Posters
BEP-48: Tracker Protocol Extension: Scrape
Controls ·  Search New posts · Mark unread

You are in: Forum / Forum / Torrent Trader / v3 Mods Completed

2022-11-16 00:19:16
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

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
2022-11-17 11:47:13
It show me the output for the html lol. also database error when I try that hash_info=xxxx

Database Error in scrape.php on line 12: Unknown column '8efe5b945f3b000ebaff01179f02a21b9a09966f' in 'where clause'. Query was: SELECT times_completed, seeders, leechers FROM torrents WHERE info_hash = 8efe5b945f3b000ebaff01179f02a21b9a09966f.
TTv3 Micro Edition
Ubuntu 20.04.6 LTS Server
Mysql Version: 10.3.39-MariaDB-0ubuntu0.20.04.2
PHP Version: 7.4.3-4ubuntu2.20
Apache Version: Apache/2.4.59 (Ubuntu)
Last edited by MicroMonkey on 2022-11-17 11:49:54
2022-11-17 21:28:57
Oh... sorry. it is supposed to be WHERE info_hash = '$info_hash' (in single quotes).

Post updated. Yeah anything comparing a string (non-integer at least), always has to have single-quotes unless the statement is prepared - then it automatically escapes as needed.

We definitely know its there lol

Last edited by STorrents2020 on 2022-11-17 21:33:57
2022-11-17 22:35:26
also appears to need
require_once("backend/BEncode.php");


after adding that I get this output using the same hash as above
d5:filesld40:8efe5b945f3b000ebaff01179f02a21b9a09966fd8:completei2e10:downloadedi1e10:incompletei0eeee5:flagsd20:min_request_intervali30eee

seems to be working
TTv3 Micro Edition
Ubuntu 20.04.6 LTS Server
Mysql Version: 10.3.39-MariaDB-0ubuntu0.20.04.2
PHP Version: 7.4.3-4ubuntu2.20
Apache Version: Apache/2.4.59 (Ubuntu)
Last edited by MicroMonkey on 2022-11-17 22:36:11
2022-11-18 00:34:25
Thats where that is! I've been looking everywhere in the GIT zip file, I know I saw some references in /backend/ but thats about it.

That makes clear sense now.. This will complete the announce code I'm on at the moment. Whew lol

---

Yup! You are all set. You got BEP-48 implemented. Clients will call it as they need. Check your access logs if you want to keep a eye on requests for /scrape?info_hash=xxx (uTorrent does it parodically, I found with stopping a torrent).
Last edited by STorrents2020 on 2022-11-18 00:36:46
Users online

No users online

Search



Statistics

    Torrents

  • Tracking: 3
  • Todays torrents: 0
  • Seeders: 0
  • Leechers: 0
  • Peers: 0
  • Downloaded: 89.96 GB
  • Uploaded: 9.86 GB

  • Members

  • We have: 838
  • New today: 0
  • Guest today: 9

  • Online

  • Total online: 2
  • Members: 0
  • Guests online: 2
  • Comments: 3
  • Messages: 1,728