导航:首页 > 文件教程 > bt文件转磁力链接

bt文件转磁力链接

发布时间:2023-06-16 00:42:24

1. BT与磁力链一样吗如果不一样,请问两者有什么区别用哪种下载方式下载文件更好

1.什么是磁力链?
答:磁力链接,简称"磁力链",最常见的用途是基于文件内容的散列函数值来链接到特定文件,生成一个唯一的文件识别符用于找到文件。磁力链接可被运行在几乎所有平台上的应用程序们使用以下载一个文件。因为磁力链接十分简洁且为纯文本格式,所以用户可以很方便地将其复制到电子邮件或即时消息中,比如BitTorrent种子。

2.磁力链能够带来什么好处?
答:所有的BT种子torrent文件均可以转换为磁力链地址(Magnet),磁力链是BT下载(P2P)的最好方式,彻底解脱了BT需要种子才能下载的历史,只需要一个简单的链接地址就可以下载,实现无种子文件跨平台下载。

3.为什么有时下载速度很慢?
答:通过磁力链下载最终还是使用的bt下载技术,使用P2P通讯协议。此协议的特点是下载的用户越多,下载速度越快,随着下载时间的增加,下载的速度也会越来越快。所以在刚开始下载的时候,速度会相对缓慢,之后会逐渐加速。

2. 如何使用python实现bt种子和磁力链接的相互转换

相应的将BT种子转换为磁力链代码为:

import bencode, hashlib, base64, urllib
torrent = open('ubuntu-12.04.2-server-amd64.iso.torrent', 'rb').read()
metadata = bencode.bdecode(torrent)
hashcontents = bencode.bencode(metadata['info'])
digest = hashlib.sha1(hashcontents).digest()
b32hash = base64.b32encode(digest)
params = {'xt': 'urn:btih:%s' % b32hash,
'dn': metadata['info']['name'],
'tr': metadata['announce'],
'xl': metadata['info']['length']}
paramstr = urllib.urlencode(params)
magneturi = 'magnet:?%s' % paramstr
print magneturi

还有另外一个效率相对较高,而且更方便的方案是安装libtorrent,在ubuntu只需要apt-get install python-libtorrent即可对应转换磁力链的代码为:
import libtorrent as bt
info = bt.torrent_info('test.torrent')
print "magnet:?xt=urn:btih:%s&dn=%s" % (info.info_hash(), info.name())

转换磁力链接为bt种子文件
下面来看一个反过程,将磁力链转化为种子文件。
1、需要先安装python-libtorrent包 ,在ubuntu环境下,可以通过以下指令完成安装:
# sudo apt-get install python-libtorrent

2、代码如下:
#!/usr/bin/env python
import shutil
import tempfile
import os.path as pt
import sys
import libtorrent as lt
from time import sleep
def magnet2torrent(magnet, output_name=None):
if output_name and \
not pt.isdir(output_name) and \
not pt.isdir(pt.dirname(pt.abspath(output_name))):
print("Invalid output folder: " + pt.dirname(pt.abspath(output_name)))
print("")
sys.exit(0)
tempdir = tempfile.mkdtemp()
ses = lt.session()
params = {
'save_path': tempdir,
'plicate_is_error': True,
'storage_mode': lt.storage_mode_t(2),
'paused': False,
'auto_managed': True,
'plicate_is_error': True
}
handle = lt.add_magnet_uri(ses, magnet, params)
print("Downloading Metadata (this may take a while)")
while (not handle.has_metadata()):
try:
sleep(1)
except KeyboardInterrupt:
print("Aborting...")
ses.pause()
print("Cleanup dir " + tempdir)
shutil.rmtree(tempdir)
sys.exit(0)
ses.pause()
print("Done")
torinfo = handle.get_torrent_info()
torfile = lt.create_torrent(torinfo)
output = pt.abspath(torinfo.name() + ".torrent")
if output_name:
if pt.isdir(output_name):
output = pt.abspath(pt.join(
output_name, torinfo.name() + ".torrent"))
elif pt.isdir(pt.dirname(pt.abspath(output_name))):
output = pt.abspath(output_name)
print("Saving torrent file here : " + output + " ...")
torcontent = lt.bencode(torfile.generate())
f = open(output, "wb")
f.write(lt.bencode(torfile.generate()))
f.close()
print("Saved! Cleaning up dir: " + tempdir)
ses.remove_torrent(handle)
shutil.rmtree(tempdir)
return output
def showHelp():
print("")
print("USAGE: " + pt.basename(sys.argv[0]) + " MAGNET [OUTPUT]")
print(" MAGNET\t- the magnet url")
print(" OUTPUT\t- the output torrent file name")
print("")
def main():
if len(sys.argv) < 2:
showHelp()
sys.exit(0)
magnet = sys.argv[1]
output_name = None
if len(sys.argv) >= 3:
output_name = sys.argv[2]
magnet2torrent(magnet, output_name)
if __name__ == "__main__":
main()

3、用法如下
# python Magnet_To_Torrent2.py <magnet link> [torrent file]

3. 如何把bt种子转换磁力链接

很简单,先用bitcomet打开这个种子新建一个任务,然后右键点击这个任务选复制Magnet
URI便把磁力连接复制到剪贴版上了
很高兴回答楼主的问题
如有错误请见谅

阅读全文

与bt文件转磁力链接相关的资料

热点内容
word编辑宏选中一段 浏览:458
微信怎么上传其他文件 浏览:220
互联网数据分析需要哪些指标 浏览:844
eps包含链接文件 浏览:167
怎么编程一些风景视频 浏览:430
苹果手机才能领的红包吗 浏览:823
js操作符 浏览:516
怎样打开db文件里的图片 浏览:820
卡仕达配置文件 浏览:419
怎样恢复直接删除的文件 浏览:587
pg数据库怎么迁移库 浏览:610
什么软件存放文件不能下载的 浏览:888
jsp的书籍推荐 浏览:330
大数据处理培训有哪些 浏览:163
苹果二手机检测多少钱 浏览:482
qq生日许愿保存到哪了 浏览:658
斗地主发牌程序c语言 浏览:996
cad安装上为什么文件夹是空的 浏览:676
mp3文件多少字节 浏览:261
哪个饰品批发网站好 浏览:944

友情链接