使用Node.JS下载Torrent

Bra*_*don 4 javascript rss bittorrent node.js

我想知道是否有人有一个如何使用NodeJS下载torrent的例子?基本上,我有一个种子的RSS Feed,我迭代并获取torrent文件URL,然后想在服务器上启动该torrent的下载.

我已经解析并在RSS中循环了,但是我已经尝试了几个npm包但它们要么已经崩溃,要么只是不稳定.如果有人有任何建议,例子,任何东西......我将非常感激.谢谢.

router.get('/', function(req, res) {
  var options = {};
  parser.parseURL('rss feed here', options, function(err, articles) {
    var i = 0;
    var torrent;
    for (var title in articles.items) {
      console.log(articles.items[i]['url']);
      //download torrent here
      i++;
    }
  });
});
Run Code Online (Sandbox Code Playgroud)

Buz*_*zut 8

您可以使用node-torrent进行此操作.

然后,下载一个torrent:

var Client = require('node-torrent');
var client = new Client({logLevel: 'DEBUG'});
var torrent = client.addTorrent('a.torrent');

// when the torrent completes, move it's files to another area
torrent.on('complete', function() {
    console.log('complete!');
    torrent.files.forEach(function(file) {
        var newPath = '/new/path/' + file.path;
        fs.rename(file.path, newPath);
        // while still seeding need to make sure file.path points to the right place
        file.path = newPath;
    });
});
Run Code Online (Sandbox Code Playgroud)

或者,为了进行更多控制,您可以使用transmission-dæmon并通过其xml-rpc协议对其进行控制.有一个称为传输的节点模块可以完成这项工作!例:

var Transmission = require('./')

var transmission = new Transmission({
    port : 9091,
    host : '127.0.0.1'
});

transmission.addUrl('my.torrent', {
    "download-dir" : "/home/torrents"
}, function(err, result) {
    if (err) {
        return console.log(err);
    }
    var id = result.id;
    console.log('Just added a new torrent.');
    console.log('Torrent ID: ' + id);
    getTorrent(id);
});
Run Code Online (Sandbox Code Playgroud)