WebTorrent Workshop

03 - Use a magnet link

Write a script that downloads the film Sintel using a magnet link rather than a .torrent file, and streams it into a <video> tag.

Tips

A magnet link is similar to a .torrent file, in that it allows you to tell WebTorrent which peers to connect to and which files to download from the network. However, unlike a .torrent file, a magnet link is quite simple. It’s just a short string of text like magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10 versus an entire file which contains lots of information.

When using a magnet link, WebTorrent will connect to peers and ask one of them to send the .torrent file before it can begin downloading pieces of the file. So this is why it’s equivalent. You get the .torrent file in the end anyway!

You can identify a torrent in many ways. WebTorrent support the following ways:

Try swapping out the torrentId in your code with the following magnet link:

const torrentId = 'magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10&dn=Sintel&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F&xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel.torrent'

Verify

If it worked, you should see the film “Sintel” start to play back! There’s no difference between the way WebTorrent handles .torrent files or magnet links!

If you are stuck, read the solution.

When you are ready, go to the next exercise.