Write a script that downloads the torrent The WIRED CD, which is a Creative Commons album released by WIRED Magazine in 2004. Display all the album’s tracks in the page as <audio>
tags.
(You can read about The WIRED CD on Wikipedia, if you’re interested.)
Start by swapping out the torrentId
in your code with the following magnet link:
const torrentId = 'https://webtorrent.io/torrents/wired-cd.torrent'
Next, you should select all the .mp3
files in the torrent by using the filter
function. It works just like find
but it selects multiple files.
Finally, add each selected file to the page.
torrent.on('ready', () => {
const files = torrent.files.filter(file => file.name.endsWith('.mp3'))
files.forEach(file => {
file.appendTo('body')
})
})
If it worked, you should see an <audio>
tag added to the page for each track in The WIRED CD. WebTorrent can handle any kind of media file that is supported by the browser!
If you are stuck, read the solution.
When you are ready, go to the next exercise.