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) }) })
// 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) {
client.add(show.eztvEpisode.magnet, {path: `output/`}, function (torrent) {