diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2014-05-14 22:43:08 +0400 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2014-05-14 22:43:08 +0400 |
commit | f5a3a1da6b2b1df4b01bff5cc6d9062421eb284c (patch) | |
tree | ac96bf70a83b24c6c5161e0d8b78e201bc6aec30 /bin | |
parent | 25c9080664a9d8814442d2e867dfeee0ff8b3a57 (diff) |
style fixes
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/cmd.js | 40 |
1 files changed, 18 insertions, 22 deletions
@@ -1,7 +1,4 @@ #!/usr/bin/env node - -// TODO: add terminal UI - var chalk = require('chalk') var clivas = require('clivas') var concat = require('concat-stream') @@ -83,15 +80,15 @@ var client = new WebTorrent({ }) client.on('error', function (err) { - clivas.line('{red:error} ' + err) + clivas.line('{red:error} ' + err.message) }) client.add(torrentId, function (err, torrent) { if (err) { - clivas.line('{red:error} ' + err) + clivas.line('{red:error} ' + err.message) process.exit(1) } - + function updateMetadata () { if (torrent) { clivas.clear() @@ -102,7 +99,7 @@ client.add(torrentId, function (err, torrent) { if (!torrent.metadata && !argv.quiet && !list) { updateMetadata() torrent.swarm.on('wire', updateMetadata) - + client.once('torrent', function () { torrent.swarm.removeListener('wire', updateMetadata) }) @@ -112,21 +109,21 @@ client.add(torrentId, function (err, torrent) { client.once('torrent', function (torrent) { if (list) { torrent.files.forEach(function (file, i) { - clivas.line('{3+bold:'+i+'} : {magenta:'+file.name+'}'); + clivas.line('{3+bold:'+i+'} : {magenta:'+file.name+'}') }) - + process.exit(0) } - + var started = Date.now() var swarm = torrent.swarm var wires = swarm.wires - var active = function(wire) { + function active (wire) { return !wire.peerChoking } - var href = 'http://'+address()+':'+swarm.port+'/' + var href = 'http://' + address() + ':' + swarm.port + '/' //var filename = engine.server.index.name.split('/').pop().replace(/\{|\}/g, '') var filename = torrent.name @@ -156,17 +153,17 @@ client.once('torrent', function (torrent) { if (argv.omx) proc.exec(OMX_EXEC+' '+href) if (argv.mplayer) proc.exec(MPLAYER_EXEC+' '+href) - var bytes = function (num) { + function bytes (num) { return numeral(num).format('0.0b') } - - var getRuntime = function () { + + function getRuntime () { return Math.floor((Date.now() - started) / 1000) } - process.stdout.write(new Buffer('G1tIG1sySg==', 'base64')); // clear for drawing + process.stdout.write(new Buffer('G1tIG1sySg==', 'base64')) // clear for drawing - var draw = function() { + function draw () { var unchoked = swarm.wires.filter(active) var runtime = getRuntime() var linesremaining = clivas.height @@ -181,18 +178,18 @@ client.once('torrent', function (torrent) { clivas.line('{80:}') linesremaining -= 8 - wires.every(function(wire) { + wires.every(function (wire) { var tags = [] if (wire.peerChoking) tags.push('choked') clivas.line('{25+magenta:'+wire.remoteAddress+'} {10:'+bytes(wire.downloaded)+'} {10+cyan:'+bytes(wire.downloadSpeed())+'/s} {15+grey:'+tags.join(', ')+'} ') peerslisted++ - return linesremaining-peerslisted > 4 + return linesremaining - peerslisted > 4 }) linesremaining -= peerslisted if (wires.length > peerslisted) { clivas.line('{80:}') - clivas.line('... and '+(wires.length-peerslisted)+' more ') + clivas.line('... and '+(wires.length - peerslisted)+' more ') } clivas.line('{80:}') @@ -206,10 +203,9 @@ client.once('torrent', function (torrent) { clivas.line('torrent downloaded {green:successfully} from {bold:'+wires.length+'} {green:peers} in {bold:'+getRuntime()+'s}!') process.exit(0) }) - + /*client.on('ready', function() { swarm.removeListener('wire', onmagnet) client.server.listen(argv.port || 8888) })*/ }) - |