{"id":26,"date":"2005-10-17T21:22:49","date_gmt":"2005-10-17T20:22:49","guid":{"rendered":""},"modified":"2007-11-20T19:30:03","modified_gmt":"2007-11-20T18:30:03","slug":"making-a-minimalist-bittorrent-client","status":"publish","type":"post","link":"http:\/\/www.hlynes.com\/?p=26","title":{"rendered":"Making a Minimalist Bittorrent Client"},"content":{"rendered":"<p>I spent the weekend sorting out bittorrent support in <a href=\"http:\/\/www.peapodpy.org.uk\" target=\"_self\">Peapod<\/a> so that it<br \/>\nwasn&#39;t quite such a mess. Previously I had hacked a version of<br \/>\nbtdownloadheadless.py so that it would exit when the download<br \/>\ncompleted. I was then shelling out to this from within Peapod.<br \/>\nObviously this is a less than ideal situation partly because it meant I had to escape URLs from the shell. So I hacked away at btdownloadheadless.py until I had a simple class I could call to do the bittorrent download. It gives almost no feedback<br \/>\nexcept a return code upon completion of the download.<\/p>\n<blockquote><p>from btclient import mytorrent<br \/>\nurl = &quot;http:\/\/www.evilgeniuschronicles.org\/audio\/egc-2005-10-10.mp3.torrent&quot;<br \/>\nsave_dir&#160; = \/tmp<br \/>\ntorrent = mytorrent(url,save_dir)<br \/>\nret = torrent.run()<br \/>\nsys.exit(ret)<\/p><\/blockquote>\n<p>If you wanted to carry on seeding rather than exiting on completion you could do:<\/p>\n<blockquote><p>torrent = mytorrent(url,save_dir,selfish=0)<br \/>\ntorrent.run()<\/p><\/blockquote>\n<p>I then added a name == &quot;__main__&quot; section into btclient so that it can be used a simple bittorrent client.<br \/>\n<strong>btclient.py http:\/\/www.evilgeniuschronicles.org\/audio\/egc-2005-10-10.mp3.torrent \/tmp<\/strong><br \/>\nor to seed:<br \/>\n<strong>btclient.py http:\/\/www.evilgeniuschronicles.org\/audio\/egc-2005-10-10.mp3.torrent \/tmp seed<\/strong><\/p>\n<p>btclient.py&#160; can be <a target=\"_self\" href=\"..\/..\/..\/archive\/scripts\/btclient.py\">downloaded from here<\/a> or alternatively see our <a target=\"_self\" href=\"http:\/\/www.peapodpy.org.uk\/downloading-peapod\/\">subversion repository<\/a> where the latest version can always be found.<\/p>\n<p>Hopefully someone will find this useful.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I spent the weekend sorting out bittorrent support in Peapod so that it wasn&#39;t quite such a mess. Previously I had hacked a version of btdownloadheadless.py so that it would exit when the download completed. I was then shelling out to this from within Peapod. Obviously this is a less than ideal situation partly because &hellip; <a href=\"http:\/\/www.hlynes.com\/?p=26\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Making a Minimalist Bittorrent Client<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-26","post","type-post","status-publish","format-standard","hentry","category-peapod"],"_links":{"self":[{"href":"http:\/\/www.hlynes.com\/index.php?rest_route=\/wp\/v2\/posts\/26"}],"collection":[{"href":"http:\/\/www.hlynes.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.hlynes.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.hlynes.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.hlynes.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=26"}],"version-history":[{"count":0,"href":"http:\/\/www.hlynes.com\/index.php?rest_route=\/wp\/v2\/posts\/26\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.hlynes.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=26"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.hlynes.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=26"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.hlynes.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=26"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}