Friday, 11 January 2013

Automating torrent downloads

I'm a big fan of the Dakar Rally. This year's Dakar is particulary interesting to me, because, not only my favourite rider Cyril Despres is looking to an easy win now that his long time rival Marc Coma didn't start the rally due to a shoulder injury, but also because after a looong reign of KTM bikes, YAMAHA IS LEADING! (YAMAHA is my favourite brand of everything.) Since I don't have Eurosport to watch the Dakar on TV, I'm "forced" to download torrents of the coverage. This means checking The Pirate Bay all the time for new torrents and downloading them as soon as they appear. This doesn't sound too difficult. But what if you're not home? Or what if you're doing something else more important? Or what if you just can't be bothered? What then? What do you do?

You write a shell script.

Shouldn't be too difficult. This way, you can put it in CRON and it will do all the checking and downloading for you. Without stalling any further, let's get to the business.

The result page on The Pirate Bay already contains magnet links for every result. That's good. We can just strip these links from curl output and feed them to KTorrent. This is how it happens:

The magnet links are extracted and written to magnets.txt.tmp. They look like this:


These are then compared to a list of existing magnets, to skip over the ones that we're already downloading. If a new magnet link is found, it is fed to KTorrent and written to the list of existing magnets for future reference.

Put that in CRON to run every 15 minutes and redirect its output to a file for debugging, like so:

This is it, more or less. If all goes well, you should have new torrents downloading and a growing list of magnets. And most important of all, you will have all the latest Dakar coverage at no fuss at all, and you'll help other fans as well by seeding torrents early. Can't stop smiling!


Later I learned you can use KTorrent RSS plugin with filters to the same effect. Well, not exactly same effect. I set up the RSS feed and a filter and got exactly one successful start of a torrent. The very next one failed. "Ambitious, but rubbish." (Clarkson)

But my script still works well!

No comments:

Post a Comment