Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

infohash-to-metadata

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

infohash-to-metadata

Torrent Metadata Downloader

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

bep9-metadata-dl

Download the metadata from peers using infohash only

This module uses bittorrent-protocol, ut_metadata and torrent-discovery modules of WebTorrent to download the info-dictionary part of a .torrent file using infohash of magnet links only.

Features

  • Simple API with callback and Promise interface
  • Find peers from the DHT network

install

npm install infohash-to-metadata

API

fetchMetadata(infohash, [opts], [callbackFn])

fetchMetadata.fromPeer(infohash, peerAddress, [opts], [callbackFn])

Optional options are:

{ 
  maxConns: 10,           // Maximum connections to peers, (default=5) 
  fetchTimeout: 30000,    // A timer scheduled to keep looking for metadata (default=20000)
  socketTimeout: 5000,    // Sets the socket to timeout after inactivity (default=5000)
  dht: DHT instance       // Use external DHT instance (default=internael DHT instance)
}

Example:

const fetchMetadata = require('infohash-to-metadata');

// infohash of ubuntu-16.04.1-server-amd64.iso
const INFO_HASH = '90289fd34dfc1cf8f316a268add8354c85334458'; 

fetchMetadata(INFO_HASH, { maxConns: 10, fetchTimeout: 30000, socketTimeout: 5000 },
  (err, metadata) => {
  if (err) {
    console.log(err);
    return;
  }
  console.log(`[Callback] ${metadata.info.name.toString('utf-8')}`);
});

Or Promise based:

const fetchMetadata = require('infohash-to-metadata');

// infohash of ubuntu-16.04.1-server-amd64.iso
const INFO_HASH = '90289fd34dfc1cf8f316a268add8354c85334458'; 

fetchMetadata(INFO_HASH, { maxConns: 10, fetchTimeout: 30000, socketTimeout: 5000 })
.then(metadata => {
  console.log(`[Promise] ${metadata.info.name.toString('utf-8')}`);
}).catch(err => {
  console.log(err);
});

Re-use DHT instance:

const DHT = require('bittorrent-dht');
const fetchMetadata = require('infohash-to-metadata');

// infohash of ubuntu-16.04.1-server-amd64.iso
const INFO_HASH = '90289fd34dfc1cf8f316a268add8354c85334458';
// infohash of ubuntu-16.04.1-desktop-amd64.iso
const INFO_HASH2 = '9f9165d9a281a9b8e782cd5176bbcc8256fd1871';
// Check https://github.com/feross/bittorrent-dht for DHT opts
const dht = new DHT({ concurrency: 32 });

// Use designated DHT instance.
fetchMetadata(INFO_HASH, { maxConns: 10, fetchTimeout: 30000, socketTimeout: 5000, dht })
.then(metadata => {
  console.log(`[Promise] ${metadata.info.name.toString('utf-8')}`);
}).catch(err => {
  console.log(err);
});

// Re-use DHT instance.
fetchMetadata(INFO_HASH2, { maxConns: 10, fetchTimeout: 30000, socketTimeout: 5000, dht })
.then(metadata => {
  console.log(`[Promise] ${metadata.info.name.toString('utf-8')}`);
}).catch(err => {
  console.log(err);
});

Download directly from a peer:

const fetchMetadata = require('infohash-to-metadata');

// infohash of ubuntu-16.04.1-server-amd64.iso
const INFO_HASH = '90289fd34dfc1cf8f316a268add8354c85334458'; 

fetchMetadata.fromPeer(INFO_HASH, 'IP_ADDRESS:PORT', { timeout: 5000 }, 
  (err, metadata) => {
  if (err) {
    console.log(err);
    return;
  }
  console.log(`[Callback] ${metadata.info.name.toString('utf-8')}`);
});

Download directly from a peer, Promise based:

const fetchMetadata = require('infohash-to-metadata');

// infohash of ubuntu-16.04.1-server-amd64.iso
const INFO_HASH = '90289fd34dfc1cf8f316a268add8354c85334458'; 

fetchMetadata.fromPeer(INFO_HASH, 'IP_ADDRESS:PORT', { timeout: 5000 })
.then(metadata => {
  console.log(`[Promise] ${metadata.info.name.toString('utf-8')}`);
}).catch(err => {
  console.log(err);
});

Keywords

FAQs

Package last updated on 21 Feb 2019

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc