X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?p=living-lab-site.git;a=blobdiff_plain;f=cis%2Fbt.py;fp=cis%2Fbt.py;h=74d43abe11eec04148a9f293bb33ff68cbd4674a;hp=928187637d430a53b70a156c55004ea7480d984c;hb=9d5e17576e133645963b8e41083baf235c5cceba;hpb=e487ab3d510e231706a1c0973973496beb25d2ff diff --git a/cis/bt.py b/cis/bt.py index 9281876..74d43ab 100644 --- a/cis/bt.py +++ b/cis/bt.py @@ -49,9 +49,10 @@ class BitTorrent: self.session = Session(sscfg) - def start_download(self, torrent, output_dir='.'): + def start_torrent(self, torrent, output_dir='.'): """ Download (leech or seed) a file via BitTorrent. + The code is adapted from Next-Share's 'BaseLib/Tools/cmdlinedl.py'. @param torrent .torrent file or URL @@ -80,3 +81,23 @@ class BitTorrent: #else: #logger.log_msg('download of torrent "%s" already started' \ #% torrent, logger.LOG_LEVEL_DEBUG) + + def stop_torrent(self, torrent, remove_content=False): + """ + Stop leeching or seeding a file via BitTorrent. + + !!! Only tested with torrents started with .tstream files. Not tested + for torrents started with URLs. + + @param torrent .torrent file or URL + @param remove_content removes downloaded file + """ + + downloads = self.session.get_downloads() + + for dl in downloads: + tdef = dl.get_def() + if torrent.find(tdef.get_name()) == 0: + self.session.remove_download(dl, remove_content) + logger.log_msg('torrent "%s" stopped' % torrent) + break