-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
bin.js
executable file
·51 lines (41 loc) · 1.32 KB
/
bin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env node
var peercast = require('./')
var prettysize = require('prettysize')
var log = require('single-line-log').stdout
var readTorrent = require('read-torrent')
if (process.argv.length < 3) {
console.error('Usage: peercast torrent-or-magnet-link')
process.exit(1)
}
readTorrent(process.argv[2], function(err, torrent) {
if (err) {
console.error(err.message)
process.exit(2)
}
var engine = peercast(torrent)
var status = 'connecting'
var hs = 0
var notChoked = function(result, wire) {
return result + (wire.peerChoking ? 0 : 1)
}
engine.on('chromecast-status', function(st) {
status = st.playerState.toLowerCase()
})
engine.on('hotswap', function() {
hs++
})
var render = function() {
var down = prettysize(engine.swarm.downloaded)
var downSpeed = prettysize(engine.swarm.downloadSpeed()).replace('Bytes', 'b')+'/s'
var up = prettysize(engine.swarm.uploaded)
var upSpeed = prettysize(engine.swarm.uploadSpeed()).replace('Bytes', 'b')+'/s'
log(
'Chromecast is '+status+'\n'+
'Connected to '+engine.swarm.wires.reduce(notChoked, 0)+'/'+engine.swarm.wires.length+' peers\n'+
'Downloaded '+down+' ('+downSpeed+') with '+hs+' hotswaps\n'+
'Uploaded '+up+ ' ('+upSpeed+')\n'
)
}
var interval = setInterval(render, 500)
render()
})