python - 您知道使用 Bittorrent 发送/接收文件的 Python 库吗?

标签 python bittorrent

我有大文件要移动到很多服务器。现在我们使用 rsync,但我想尝试使用 bittorent。

我正在研究 Deluge 的代码,这是一个 Python bittorent 客户端,但它使用了 twisted 并且非常复杂。你知道什么高层次的东西吗?

编辑:我刚刚读到 Facebook 使用 Bittorent 进行代码部署。也许他们为此发布了他们的库,但我找不到它。听说过吗?

最佳答案

我绝对推荐libtorrent-rasterbar .它是一个带有 Python 绑定(bind)的 C++ 库。为 Deluge、Transmission、Miro 和许多其他比特流客户端提供支持的同一个客户端。

与其他 libtorrent(属于 rTorrent 项目的一部分)相比,这个正在积极开发并支持所有现代协议(protocol)扩展,如 DHT、元数据传输,甚至一些专有的 uTorrent 扩展,如对等交换 (PEX) .

API 有很好的文档记录。

正如您从以下功能齐全的简单客户端示例中看到的那样,您无需了解底层协议(protocol)的每一点(当然,当您了解时它会帮助很大):

#!/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'

附言Facebook 在 http://developers.facebook.com/opensource/ 有一个专门的开源项目页面。 .没有列出 bittorrent 实现。

关于python - 您知道使用 Bittorrent 发送/接收文件的 Python 库吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4750432/

相关文章:

vim - .torrent 文件包含乱码

python - Pygame: Sprite 因运动方向而变化

python - Numpy 数组 : Changing the values of the last column when lines of a 2d-array are equal to lines of another 2d-array

python - django-nose collect-only 运行测试

python - 谷歌 foobar 挑战 EOFError

java - java 中的 Torrent 解析器

python - beautifulsoup find_all 无法获取div数据

java - 如何使用对等点(二进制模型)从跟踪器响应中读取正确的端口

c# - 无法使用 monotorrent ("no connection could be made because the target machine actively refused it"下载种子文件)