Pirate Bay uptime has always been an issue because of the of the pressure and legal issues that they’re constantly dealing with. This can be frustrating when it’s down but you just want to find a torrent for some legal Linux ISO’s or public domain content from their extensive torrent index.
I found out that the folks at The Pirate Bay host a compressed copy of their torrent database for offline use in these circumstances. The bad news is that it’s a little bit convoluted for most people to know how to use this raw data. The good news is that if you use a *nix system like MacOS or Linux then you probably have all the tools that you need to make the database dump useful without any third party software.
I’ll keep this short and sweet with some links in case you want to elaborate or know the gritty details of each tool.
First of all we can fetch the database dump from the Pirate Bay with wget:
The file we download is a tarred and gzipped CSV file. To extract the CSV file:
tar xvzf torrent_dump_full.csv.gz
This CSV file is a massive index of every single torrent in the following format:
Date Added; Encoded Magnet Link Data; Torrent Name; Size in Bytes
2005-Jan-01 19:01:15;FctnA/YZJJ8RZ43S6PQytmuVlj0=;"ManDrake 10.1 DVD iso";4676982859
To do a quick search of the torrents in the dump we can use
grep with the
-i option for case insensitivity. Here I search for my favorite Linux distro from 2005:
grep -i mandrake torrent_dump_full.csv
So how can we make sense of this information use it to download the files we’re after?
The encoded string in the second field has been converted to hex and then converted to base 64.
If we decode this string then we can use it to create a magnet link for use in our torrent application.
We can pipe the output through base64 and xxd tools like so:
echo FctnA/YZJJ8RZ43S6PQytmuVlj0= | base64 --decode | xxd -l 32 -p
The output of the above command can be appended to BitTorrent info hash (BTIH) URI:
Then you have a complete magnet URI that you can open in your favorite torrent client to download files!
LIMITATIONS (and WARNINGS!)
- You cannot see the reviews, descriptions or file contents from the CSV dump like you can on the website
- Do not download executable because duh
- I’m not condoning piracy
Want to learn more about how this all works?
This was a really fun opportunity to apply a few things I’ve learned. I encourage you to do the same!
The basecs podcast is great for some great explainers of how encoding works: https://medium.com/basecs/hexs-and-other-magical-numbers-9785bc26b7ee
Other relevant links: