torrent.on('done', () => { if (!argv.quiet) { const numActiveWires = torrent.wires .reduce((num, wire) => num + (wire.downloaded > 0), 0) clivas.line('') clivas.line( 'torrent downloaded {green:successfully} from {bold:%s/%s} {green:peers} ' + 'in {bold:%ss}!', numActiveWires, torrent.numPeers, getRuntime() ) } torrentDone() })
function runSeed (input) { if (path.extname(input).toLowerCase() === '.torrent' || /^magnet:/.test(input)) { // `webtorrent seed` is meant for creating a new torrent based on a file or folder // of content, not a torrent id (.torrent or a magnet uri). If this command is used // incorrectly, let's just do the right thing. runDownload(input) return } const client = new WebTorrent({ blocklist: argv.blocklist }) client.on('error', fatalError) client.seed(input, { announce: argv.announce, torrentPort: argv['torrent-port'], dhtPort: argv['dht-port'] }, torrent => { if (argv.quiet) { console.log(torrent.magnetURI) } drawTorrent(torrent) }) }
torrent.on('infoHash', () => { if ('select' in argv) { torrent.so = argv.select.toString() } if (argv.quiet) return updateMetadata() torrent.on('wire', updateMetadata) function updateMetadata () { clivas.clear() clivas.line( '{green:fetching torrent metadata from} {bold:%s} {green:peers}', torrent.numPeers ) } torrent.on('metadata', () => { clivas.clear() torrent.removeListener('wire', updateMetadata) clivas.clear() clivas.line('{green:verifying existing torrent data...}') }) })
const torrentFilePath = `${argv.out}/${this.infoHash}.torrent` if (argv.quiet) { return
function drawTorrent (torrent) { if (!argv.quiet) { process.stdout.write(Buffer.from('G1tIG1sySg==', 'base64')) // clear for drawing drawInterval = setInterval(draw, 1000)