tracker-scrape.md
1 # Count the number of peers using the `scrape` feature of torrent trackers 2 3 Here's a full example with `browserify`. 4 5 ``` 6 npm install browserify parse-torrent bittorrent-tracker 7 ``` 8 9 `scrape.js`: 10 11 ```js 12 var Tracker = require('bittorrent-tracker') 13 var magnet = require('magnet-uri') 14 15 var magnetURI = "magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d&dn=sintel.mp4&tr=udp%3A%2F%2Fexodus.desync.com%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.internetwarriors.net%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&tr=wss%3A%2F%2Ftracker.webtorrent.io&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel-1024-surround.mp4" 16 17 var parsedTorrent = magnet(magnetURI) 18 19 var opts = { 20 infoHash: parsedTorrent.infoHash, 21 announce: parsedTorrent.announce, 22 peerId: new Buffer('01234567890123456789'), // hex string or Buffer 23 port: 6881 // torrent client port 24 } 25 26 var client = new Tracker(opts) 27 28 client.scrape() 29 30 client.on('scrape', function (data) { 31 console.log(data) 32 }) 33 ``` 34 35 Bundle up `scrape.js` and it's dependencies into a single file called `bundle.js`: 36 37 ```bash 38 browserify scrape.js -o bundle.js 39 ``` 40 41 `index.html`: 42 43 ```js 44 <script src="bundle.js"></script> 45 ``` 46 47 Open `index.html` in your browser.