Bashpodder and BitTorrent

Bashpodder, in case you are not already familiar with it, is a command line tool for downloading podcasts.
I like it because it's unintrusive and can be run from a cron job.
Which means when I get home in the evening I can just check today's
download directory and see what cool stuff I have to listen to.


I did some cleaning of the scrip on saturday afternoon to make it deal
with disconnection in a more sane manner, and also to take advantage of
wget's ability to recomence a download that has already started. This
means that bashpodder should be a bit less of bandwidth whore in the
future.

I subscribed to the RSS feed of evilgeniuschronicles.
All was well until I looked in my download directory to see lots of
*.mp3.torrent files. Bummer.  Drunk on success I thought "I shall
now go forth and add bittorrent support to bashpodder". BitTorrent is
wriiten in python so I thought there was probably a good chance to get
where I wanted to go since I already know python. There is even a
command-line script called btdownloadheadles.py. However like most
bittorrent clients this stays open until it's explicitly killed. This
wasn't the behaviour I was looking for but I figured it wouldn't take
too much tweaking to get it to exit on success or failure. Six hours
later at four in the morning I finally gave up and went to bed.
Throwing sys.exit(0) anywhere in the code just disn't seem to work.

After a good sleep it took me about ten minutes to work out what had
been outfoxing me for hours. The bittorrent code treats a sys.exit(0)
as an error state. So you end up in the generic error function. By
adding a sys.exit(1) into the error function I could finally get the
damn thing to exit. I tidied it up to add some checks in the error
function so that it calls sys.exit(0) is it got there by receiving
sys.exit(0) else it exits with a non-zero error code.

Of course now that I I've got working code the egr feed has gone down so I can't test it. It'll just have to wait till tommorow.

Leave a Reply

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