webtorrent-health

Get health info about a webtorrent file or magnet link


Keywords
webtorrent, torrent, health, peers, tracker, swarm, seeders, bittorrent, web, browser, health-info, webtorrent-health
License
MIT
Install
npm install webtorrent-health@1.1.1

Documentation

webtorrent-health

NPM Version Build Status Dependency Status Standard - Javascript Style Guide

Get health info about a webtorrent file or magnet link

Install

npm install webtorrent-health

Usage

The param torrentId can be a webtorrent file or magnet link, for more info check out parse-torrent.

webtorrentHealth(torrentId [, opts], callback)
var webtorrentHealth = require('webtorrent-health')
var magnet = 'magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d&dn=sintel.mp4&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com'

webtorrentHealth(magnet, function (err, data) {
  if (err) return console.error(err)

  console.log('average number of seeders: ' + data.seeds)
  console.log('average number of leechers: ' + data.peers)
  console.log('ratio: ', +(Math.round((data.peers > 0 ? data.seeds / data.peers : data.seeds) +'e+2') + 'e-2'))
})

You can also use Promises/A+:

var webtorrentHealth = require('webtorrent-health')
var magnet = 'magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d&dn=sintel.mp4&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com'

webtorrentHealth(magnet).then(function (data) {
  console.log('average number of seeders: ' + data.seeds)
  console.log('average number of leechers: ' + data.peers)
  console.log('ratio: ', +(Math.round((data.peers > 0 ? data.seeds / data.peers : data.seeds) +'e+2') + 'e-2'))
}).catch(console.error.bind(console))

If you couldn't scrape any of the trackers you will not get any errors, but the returned data will look like this:

{
  seeds: 0,
  peers: 0,
  extra: [...]
}

The attribute extra is an Array of Objects, that contains more info about the each tracker. Example:

[
  {
    tracker: 'wss://tracker.openwebtorrent.com',
    seeds: 561,
    peers: 12967,
    downloads: 561,
    response_time: 229
  },
  {
    tracker: 'wss://tracker.btorrent.xyz',
    seeds: 601,
    peers: 19119,
    downloads: 601,
    response_time: 705
  },
  {
    tracker: 'wss://tracker.badtracker.com',
    error: 'connection error to wss://tracker.badtracker.com'
  }
]

Additional params

  • opts.trackers: additional trackers to scrape on top of the ones torrentId has.
    • Type: an Array of Strings
    • Example:
webtorrentHealth(torrentId, {
    trackers: ['wss://tracker.openwebtorrent.com']
}, function (err, data) {
  // Do something
})
  • opts.blacklist: don't scrape some trackers.
    • Type: an Array of Strings (each string can be a regex)
    • Example:
webtorrentHealth(torrentId, {
    blacklist: [
        'openbittorrent'    // will blacklist any tracker containing that string in its URI
    ]
}, function (err, data) {
  // Do something
})
  • opts.timeout: timeout in milliseconds for each request to scarpe the tracker. Default is 1000.
    • Type: number
    • Example:
webtorrentHealth(torrentId, {
    timeout: 1500
}, function (err, data) {
  // Do something
})

License

MIT. Copyright (c) Alex