node-inspector &
node --debug-brk test.js
在 chrome 中调试
'use strict';
var P2PSpider = require('../lib');
var p2p = P2PSpider({
nodesMaxSize: 20, // be careful
maxConnections: 40, // be careful
timeout: 5000
});
p2p.ignore(function (infohash, rinfo, callback) {
// false => always to download the metadata even though the metadata is exists.
var theInfohashIsExistsInDatabase = false;
callback(theInfohashIsExistsInDatabase);
});
var fs = require('fs');
var path = require('path');
p2p.on('metadata', function (metadata) {
console.log(metadata);
var rec={};
rec._name=metadata.info['name'].toString();
rec.publisher=metadata.info['publisher'].toString();
rec.magnet=metadata.magnet;
var outp=JSON.stringify(rec);
fs.appendFile(path.join(__dirname, 'metadata.json'),JSON.stringify(outp)+'
' , function (err) {
if (err) throw err;
console.log("Export metadata Success!");
});
});
p2p.listen(6881, '0.0.0.0');