npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

webtorrent-health

v1.2.0

Published

Get health info about a webtorrent file or magnet link

Downloads

3,149

Readme

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