2011-01-20 57 views
6

我有大文件移動到很多服務器。現在我們使用rsync,但我想嘗試一下bittorent。你知道使用Bittorent發送/接收文件的Python庫嗎?

我在研究Deluge的代碼,這是一個Python bittorent客戶端,但它使用了扭曲並且非常複雜。你知道什麼水平嗎?

編輯:我剛剛看到Facebook使用Bittorent代碼部署。也許他們爲此發佈了自己的lib,但是我找不到它。聽說過嗎?

+2

http://code.google.com/p/python-libtorrent/可能會對您有所幫助。它是一個圍繞C++ libtorrent庫的Python包裝器。 – user225312 2011-01-20 17:30:12

+0

它已被納入洪水計劃,現在用1000行代碼繪製,沒有食譜。 – 2011-01-20 17:44:34

回答

5

我絕對推薦libtorrent-rasterbar。這是一個使用Python綁定的C++庫。與Deluge,Transmission,Miro和其他許多BitTorrent客戶一樣。

與另一個libtorrent(屬於rTorrent項目的一部分)相比,它正處於積極的發展階段,並支持所有現代協議擴展,如DHT,元數據傳輸,甚至一些專有的uTorrent擴展,如對等交換)。

該API有很好的文檔記錄。

正如你可以從下面的全功能簡單的客戶端例子中看到的,你不需要了解底層協議的每一點(當然,它有助於當你做了很多):

#!/bin/python 
# Copyright Arvid Norberg 2008. Use, modification and distribution is 
# subject to the Boost Software License, Version 1.0. (See accompanying 
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 


import libtorrent as lt 
import time 
import sys 

ses = lt.session() 
ses.listen_on(6881, 6891) 

info = lt.torrent_info(sys.argv[1]) 
h = ses.add_torrent({'ti': info, 'save_path': './'}) 
print 'starting', h.name() 

while (not h.is_seed()): 
    s = h.status() 

    state_str = ['queued', 'checking', 'downloading metadata', 'downloading', \ 
     'finished', 'seeding', 'allocating', 'checking fastresume'] 
    print '\r%.2f%% complete (down: %.1f kb/s up: %.1f kB/s peers: %d) %s' % \ 
     (s.progress * 100, s.download_rate/1000, s.upload_rate/1000, \ 
     s.num_peers, state_str[s.state]), 
    sys.stdout.flush() 

    time.sleep(1) 

print h.name(), 'complete' 

PS Facebook在http://developers.facebook.com/opensource/上有專門的開源項目頁面。沒有列出任何bittorrent實現。

2

最初的BitTorrent客戶端是用Python編寫的。你檢查過了嗎?

+1

距離高度很遠。如果你不知道協議,你就卡住了。 – 2011-01-20 17:42:09

相關問題