client.on('error', function (err) { console.error('Error: ' + err.message) loading.style.display = 'none'; alert('An error occured. Please try again.') location.reload() })
/*displayFile(fileindex,locationid){ this.torrent.files[fileindex].renderTo(locationid) }*/ removeTorrent(){ //this.client.remove(torrentId, [function callback (err) {}]) if ((this.torrentId!='')&&(this.torrentId!=undefined)) { this.client.remove(this.torrentId) console.log('remove torrent',this.torrentId) } }
client.seed(filePath, torrent => { console.log('torrentId (info hash):', torrent.infoHash) // console.log('torrentId (magnet link):', torrent.magnetURI) })
destroyClient(){ //this.client.destroy([function callback (err) {}]) this.client.destroy() }
client.add(torrentId, torrent => { const files = torrent.files let length = files.length // Stream each file to the disk files.forEach(file => { const source = file.createReadStream() const destination = fs.createWriteStream(file.name) source.on('end', () => { console.log('file:\t\t', file.name) // close after all files are saved length -= 1 if (!length) process.exit() }).pipe(destination) }) })
// Listen for for input document.querySelector('form').addEventListener('submit', function (e) { e.preventDefault() // Clear out contents document.getElementById('title').innerHTML = ''; progressBar.value = 0 progressBar.style.display = 'none' document.querySelector('.output').innerHTML = ''; // Get magnet var torrentId = document.querySelector('form input[name=magnet]').value // Show loading spinner loading.style.display = 'block'; ipc.send('downloads-path') ipc.on('downloads-path-reply', function (event, path) { const downloadsPath = path // Start downloading torrent, callback to onTorrent client.add(torrentId, { path: downloadsPath }, onTorrent) }) })
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) }) }
client.add(show.eztvEpisode.magnet, {path: `output/`}, function (torrent) {
// Listen for a recent file or open file click and append that file to the DOM ipc.on('open-file-reply', function (event, filePath) { var fileName = filePath.split('/').slice(-1)[0] document.getElementsByClassName('output')[0].innerHTML = '' if (fileName.endsWith('.mp4')) { log(fileName) log('<video controls autoplay><source src="' + filePath + '" type="video/mp4"></video>') } else if (fileName.endsWith('.torrent')) { var torrentId = filePath // Show loading spinner loading.style.display = 'block'; ipc.send('downloads-path') ipc.on('downloads-path-reply', function (event, path) { const downloadsPath = path // Start downloading torrent, callback to onTorrent client.add(torrentId, { path: downloadsPath }, onTorrent) }) } progressBar.value = 0 progressBar.style.display = 'none' })
this.client.add(magnetURI, { path: path.join(__dirname,'../cached/') }, function (torrent) {