Skip to content

Instantly share code, notes, and snippets.

@DiegoRBaquero
Created May 8, 2016 19:04
Show Gist options
  • Save DiegoRBaquero/4235c7283e7ff579cdd093305803e799 to your computer and use it in GitHub Desktop.
Save DiegoRBaquero/4235c7283e7ff579cdd093305803e799 to your computer and use it in GitHub Desktop.
File Download with WebTorrent
<html>
<body>
<script src="https://cdn.jsdelivr.net/webtorrent/latest/webtorrent.min.js"></script>
<script>
var client = new WebTorrent()
client.add('https://webseed.btorrent.xyz/juanpabloaj/other-page.torrent', function (torrent) {
// Got torrent metadata!
console.log('Client is downloading:', torrent.infoHash)
torrent.files[0].getBlobURL(function(err, url) {
if (err) return console.log(err)
var a = document.createElement('a')
a.target = '_blank'
a.download = torrent.files[0].name
a.href = url
a.textContent = 'Download ' + torrent.files[0].name
document.body.appendChild(a)
})
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment