Downloading Directly From Torrentz

2017 Update: now works with Torrentz2

The popular torrent search engine, Torrentz.eu does not provide direct links to download torrents. Normally, one would have to pick one of the available torrent websites at the top of the page in order to get a .torrent file or magnet link. However, I recently noticed that all the information needed to generate a .torrent file or magnet link is actually available on the page itself, namely the info hash and a list of trackers. As such I wrote some JavaScript to generate a magnet link.

var infoHash = document.querySelector("div.trackers h2").childNodes[1].textContent.substring(6),
displayName = document.querySelector("div.downlinks h2 span").textContent,
trackers = document.querySelectorAll("div.trackers dl dt"),
a = document.createElement("a"),
magnet = "magnet:?xt=urn:btih:" + infoHash + "&dn=" + displayName;
for (var i = 0; i < trackers.length; i++) {
    magnet += "&tr=" + trackers[i].textContent;
}
console.log(magnet);
window.location = magnet;

The last line is optional and performs the equivalent of clicking on the link. To convert the torrent hash above the trackers list into a clickable link instead of automatically opening the magnet handler, replace window.location = magnet with:

var hashNode = document.querySelector("div.trackers h2").childNodes[1],
hashLink = document.createElement('a');
hashLink.textContent = hashNode.textContent;
hashLink.setAttribute('href', magnet);
hashNode.parentNode.replaceChild(hashLink, hashNode);

For the sake of convenience, I have also made a bookmarklet that will automatically start a torrent download when clicked (assuming that you are currently on a Torrentz.eu torrent page). Drag this button onto your bookmarks toolbar and you will be good to go:

Torrentz Download

And here is one that “linkifies” the torrent hash instead of automatically downloading:

Torrentz Linkify

Leave a Reply

Your email address will not be published. Required fields are marked *


4 × = twenty