将bittorrent磁铁链接转换为.torrent文件。
magnet2torrent的Python项目详细描述
Magnet2Torrent公司
纯python项目,将磁铁链接转换为.torrent文件。 我们的目标是尽快完成。在
入门
安装
pip install magnet2torrent
用法
下载ubuntu iso torrent。在
^{pr2}$作为HTTP服务器运行。在
magnet2torrent serve
将其作为启用了许多功能的HTTP服务器运行。在
magnet2torrent --use-dht --dht-state-file dht.state --torrent-cache-folder torcache serve --apikey secretkey
从python使用
importasynciofrommagnet2torrentimportMagnet2Torrent,FailedToFetchExceptionasyncdeffetch_that_torrent():m2t=Magnet2Torrent("magnet:?xt=urn:btih:e2467cbf021192c241367b892230dc1e05c0580e&dn=ubuntu-19.10-desktop-amd64.iso&tr=https%3A%2F%2Ftorrent.ubuntu.com%2Fannounce&tr=https%3A%2F%2Fipv6.torrent.ubuntu.com%2Fannounce")try:filename,torrent_data=awaitm2t.retrieve_torrent()exceptFailedToFetchException:print("Failed")asyncio.run(fetch_that_torrent())
如果要使用DHT进行检索,则必须引导并运行它。在
importasyncioimportosfrommagnet2torrentimportMagnet2Torrent,FailedToFetchException,settingsDHT_STATE_FILE="/tmp/dht.state"asyncdefstart_dht():ifos.path.exists(DHT_STATE_FILE):dht_server=DHTServer.load_state(DHT_STATE_FILE)awaitdht_server.listen(settings.DHT_PORT)else:dht_server=DHTServer()awaitdht_server.listen(settings.DHT_PORT)awaitdht_server.bootstrap(settings.DHT_BOOTSTRAP_NODES)returndht_serverasyncdeffetch_that_torrent(dht_server):m2t=Magnet2Torrent("magnet:?xt=urn:btih:e2467cbf021192c241367b892230dc1e05c0580e&dn=ubuntu-19.10-desktop-amd64.iso",dht_server=dht_server)try:filename,torrent_data=awaitm2t.retrieve_torrent()exceptFailedToFetchException:print("Failed")dht_server=asyncio.run(start_dht())asyncio.run(fetch_that_torrent(dht_server))dht_server.save_state(DHT_STATE_FILE)
许可证
这个项目是在麻省理工学院许可下授权的-有关详细信息,请参阅LICENSE.md文件
DHT部分从bmueller/kademlia派生-它的许可证可以是 在dht文件夹或原始项目中找到。在
- 项目
标签: