libtorrent上的简单torrent客户端
sstc的Python项目详细描述
在libtorrent python绑定之上构建的愚蠢、简单的torrent客户端。
允许您添加Torrent文件和Magnet并接收LibTorrent警报。就这些!
- 免费软件:wtfpl
功能
- 待办事项
完整示例
这个例子展示了如何添加磁铁uri以及如何创建警报处理程序。
警报处理程序方法应命名为“on_alert”,其中alert的类型为alert 去处理。
所有方法都将接收会话作为第一个参数和警报 作为第二个。
请注意,这个例子并不详尽。
# coding: utf-8importsysimportosimporttimeimportloggingfromsstc.sstcimportTorrentClientlogging.basicConfig(level=logging.DEBUG)logger=logging.getLogger(__name__)classAlertHandler(object):defon_torrent_added_alert(self,session,alert):logger.debug("on_torrent_added_alert")defon_state_changed_alert(self,session,alert):logger.debug("on_state_changed_alert")logger.debug(alert.message())defon_torrent_resumed_alert(self,session,alert):logger.debug("on_torrent_resumed_alert")defon_torrent_checked_alert(self,session,alert):logger.debug("on_torrent_checked_alert")handler=alert.handleinfo=handler.get_torrent_info()files=info.files()# Do something with torrent infos, like filter files to download# torrent was added paused, we resume ithandler.resume()defon_torrent_finished_alert(self,session,alert):logger.debug("on_torrent_finished_alert")# if you want to remove the torrent immediately :#session.remove_torrent(handler)defon_piece_finished_alert(self,session,alert):logger.debug("on_torrent_finished_alert")handler=alert.handledefon_block_finished_alert(self,session,alert):logger.debug("on_block_finished_alert")handler=alert.handledefon_file_completed_alert(self,session,alert):logger.debug("on_file_completed_alert")handler=alert.handleinfo=handler.get_torrent_info()f=info.file_at(alert.index)logger.debug("%s : completed",f.path)defmain():# starts client with 100Mib/s download limit# and 10Mib/s uploadlimitclient=TorrentClient(download_rate_limit=100<<20,upload_rate_limit=10<<20,)# start client alert dispatcherclient.start()to_download=[# support local torrentfile"./big_buck_bunny.torrent"# also magnet url"magnet:?xt=urn:btih:0E876CE2A1A504F849CA72A5E2BC07347B3BC957&dn=big+buck+bunny+720p+psiclone&tr=udp%3A%2F%2Fopen.demonii.com%3A1337%2Fannounce",# also from http/https url"http://www.frostclick.com/torrents/video/animation/Big_Buck_Bunny_1080p_surround_frostclick.com_frostwire.com.torrent",]try:foriteminto_download:client.add(item,is_paused=True,alert_handler=AlertHandler())# Blocking loopclient.loop()except(KeyboardInterrupt,Exception)ase:client.stop()if__name__=="__main__":main()
历史记录
0.1.0(2015-01-11)
- pypi上的第一个版本。