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,
fetchTimeout: 30000,
socketTimeout: 5000,
dht: DHT instance
}
Example:
const fetchMetadata = require('infohash-to-metadata');
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');
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');
const INFO_HASH = '90289fd34dfc1cf8f316a268add8354c85334458';
const INFO_HASH2 = '9f9165d9a281a9b8e782cd5176bbcc8256fd1871';
const dht = new DHT({ concurrency: 32 });
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);
});
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');
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');
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);
});