magnet-to-torrent

1.0.8 • Public • Published

magnet-to-torrent

convert a magnet uri to a torrent download link

Install

npm install --save magnet-to-torrent

How to use

var magnetToTorrent = require('magnet-to-torrent');
 
var magnet = '< a valid magnet uri >';
magnetToTorrent.getLink(magnet)
    .then( function(torrentLink){
        console.log(torrentLink); // torrent url as string
    })
    .catch(function(error){
        console.error(error); // couldn't get a valid link
    });

Check if URI is a Magnet URI

The following verifies if the magnet uri provided is formatted correctly.

var bool = magnetToTorrent.isMagnet(magnet); // returns boolean

Default Services Used

The library will attempt to retrieve a working torrent link from the following services, respectively:

Adding a Conversion Service

Each service takes in hash as a parameter and uses it to build the download link in the format of how the said service allows a user to download torrents. The library tests if the torrent is cached by the service and responds with the first url that has the torrent available.

You can add your own service before attempting to convert magnets.

See snippet below.

eg.

var service = function(hash){
    return `http://reflektor.karmorra.info/torrent/${hash}.torrent`;
};
 
magnetToTorrent.addService(service);
 
/**
 OR:
 Optionally, use a second parameter to push the service to the top of the stack
 This will ensure your service is called first
**/
magnetToTorrent.addService(service, true);

Notes:

  • hash is the torrent hash extracted from the magnet uri
  • This is an experiment but should work fine.

Report any issues.

Credits

Package Sidebar

Install

npm i magnet-to-torrent

Weekly Downloads

7

Version

1.0.8

License

MIT

Unpacked Size

7.89 kB

Total Files

4

Last publish

Collaborators

  • lwhiteley