Skip to content

Commit 4595824

Browse files
committed
add tracker scrape example
1 parent 2dabde8 commit 4595824

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

examples/tracker-scrape.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
// These values don't matter
16+
var peerId = new Buffer('01234567890123456789')
17+
var port = 6889
18+
19+
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"
20+
21+
var parsedTorrent = magnet(magnetURI)
22+
var client = new Tracker(peerId, port, parsedTorrent)
23+
24+
client.scrape()
25+
26+
client.on('scrape', function (data) {
27+
console.log(data)
28+
})
29+
```
30+
31+
Bundle up `scrape.js` and it's dependencies into a single file called `bundle.js`:
32+
33+
```bash
34+
browserify scrape.js -o bundle.js`
35+
```
36+
37+
`index.html`:
38+
39+
```js
40+
<script src="bundle.js"></script>
41+
```
42+
43+
Open `index.html` in your browser.

0 commit comments

Comments
 (0)