[英]I can't download torrent from public tracker libtorrent
我在python中使用libtorrent
模塊下載torrent。 我可以從私人跟蹤器下載torrent,但不能從公共跟蹤器下載。 我嘗試使用各種種子,我可以使用“傳輸”下載。 我檢查了4個不同的連接,都是一樣的。
def downloadTorrent(torrent):
"""
Download torrent using libtorrent library.
Torrent will be stored at the current directory.
"""
ses = lt.session()
ses.listen_on(6881, 6891)
info = lt.torrent_info(torrent)
h = ses.add_torrent({'ti': info, 'save_path': './'})
ses.start_dht()
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'
當我嘗試時,我得到:
0.00% complete (down: 0.0 kb/s up: 0.0 kB/s peers: 0) downloading
它停在那里。
我不知道它是否有幫助,但私人跟蹤器使用的是http
而不是udp
,並且它不允許使用DHT。
您沒有真正解釋如何在downloadTorrent
函數中提供torrent文件。 如果您已經在計算機上下載了torrent文件,則您的功能有效。
如果你想提供一個torrent url作為這個函數的參數,你需要讀取http響應作為字節,如torrent = lt.bdecode(urllib2.urlopen(torrent_url, 'rb').read())
這是與python 2.7一起使用的完整代碼:
import libtorrent as lt
import urllib2
public_torrent = 'http://releases.ubuntu.com/14.04.3/ubuntu-14.04.3-desktop-amd64.iso.torrent'
def downloadTorrent(torrent_url):
"""
Download torrent using libtorrent library.
Torrent will be stored at the current directory.
"""
ses = lt.session()
ses.listen_on(6881, 6891)
# read torrent file as bytes
torrent = lt.bdecode(urllib2.urlopen(torrent_url, 'rb').read())
info = lt.torrent_info(torrent)
h = ses.add_torrent({'ti': info, 'save_path': './'})
ses.start_dht()
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'
downloadTorrent(public_torrent)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.