Socket
Socket
Sign inDemoInstall

webtorrent-health

Package Overview
Dependencies
56
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    webtorrent-health

Get health info about a webtorrent file or magnet link


Version published
Weekly downloads
369
decreased by-7.05%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

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

Keywords

FAQs

Last updated on 15 Oct 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc