Created
May 8, 2016 19:04
-
-
Save DiegoRBaquero/4235c7283e7ff579cdd093305803e799 to your computer and use it in GitHub Desktop.
File Download with WebTorrent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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