Skip to content
Convert magnet to torrent (independent of third-party services)
JavaScript
Branch: master
Clone or download
Latest commit 1e32edd Apr 13, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
mod/torrent-stream [Simplify] Apr 7, 2019
.gitattributes
.gitignore
LICENSE Initial commit Apr 5, 2019
README.md [Add] Timeout option Apr 13, 2019
index.js [Add] Timeout option Apr 13, 2019
package.json v1.3.0 Apr 13, 2019
test.js [Update] test Apr 7, 2019

README.md

magnet2torrent

This module uses torrent-stream to download metadata of magnet links only, without creating any temp file.

Install

npm i magnet2torrent-js

API

m2t = new Magnet2torrent(options)

Optional options are:

{
    trackers = [],                  // {Array<string>} Trackers to use, default is []
    addTrackersToTorrent = false,   // {boolean} Default is false
    timeout = 60                    // {number} Timeout seconds, set to 0 will disable, default is 0
}

m2t.getTorrentBuffer(magnet)

magnet can be a magnet link magnet:?xt=urn:btih:90289fd34dfc1cf8f316a268add8354c85334458
or a hash 90289fd34dfc1cf8f316a268add8354c85334458

Example

Download torrent file simply

const Fs = require('fs');
const Magnet2torrent = require('magnet2torrent-js');

// ubuntu-16.04.1-server-amd64.iso
let magnet = 'magnet:?xt=urn:btih:90289fd34dfc1cf8f316a268add8354c85334458';

let m2t = new Magnet2torrent({
    timeout: 60
});

m2t.getTorrentBuffer(magnet).then(buffer => {
    Fs.writeFileSync('test.torrent', buffer);
}).catch(e => {
    console.error('Timeout or error occured');
});

Use custom trackers and write them to torrent file

const Fs = require('fs');
const Magnet2torrent = require('magnet2torrent-js');

// https://github.com/ngosang/trackerslist
const trackers = [
    'udp://tracker.coppersurfer.tk:6969/announce',
    'udp://tracker.open-internet.nl:6969/announce',
    'udp://tracker.leechers-paradise.org:6969/announce',
    'http://tracker3.itzmx.com:6961/announce',
    'http://tracker1.itzmx.com:8080/announce',
    'udp://bt.xxx-tracker.com:2710/announce'
];

// ubuntu-16.04.1-server-amd64.iso
let magnet = 'magnet:?xt=urn:btih:90289fd34dfc1cf8f316a268add8354c85334458';

let m2t = new Magnet2torrent({
    trackers,
    addTrackersToTorrent: true
});

m2t.getTorrentBuffer(magnet).then(buffer => {
    Fs.writeFileSync('test.torrent', buffer);
});
You can’t perform that action at this time.