文件管理 · 2023年8月6日

bt文件转磁力链接|BT与磁力链一样吗如果不一样

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

1.什么是磁力链? 答:磁力链接,简称"磁力链",最常见的用途是基于文件内容的散列函数值来链接到特定文件,生成一个唯一的文件识别符用于找到文件。磁力链接可被运行在几乎所有平台上的应用程序们使用以下载一个文件。因为磁力链接十分简洁且为纯文本格式,所以用户可以很方便地将其复制到电子邮件或即时消息中,比如BitTorrent种子。 2.磁力链能够带来什么好处? 答:所有的BT种子torrent文件均可以转换为磁力链地址(Magnet),磁力链是BT下载(P2P)的最好方式,彻底解脱了BT需要种子才能下载的历史,只需要一个简单的链接地址就可以下载,实现无种子文件跨平台下载。 3.为什么有时下载速度很慢? 答:通过磁力链下载最终还是使用的bt下载技术,使用P2P通讯协议。此协议的特点是下载的用户越多,下载速度越快,随着下载时间的增加,下载的速度也会越来越快。所以在刚开始下载的时候,速度会相对缓慢,之后会逐渐加速。

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

相应的将BT种子转换为磁力链代码为:import bencode, hashlib, base64, urllibtorrent = 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' % paramstrprint magneturi还有另外一个效率相对较高,而且更方便的方案是安装libtorrent,在ubuntu只需要apt-get install python-libtorrent即可对应转换磁力链的代码为:import libtorrent as btinfo = 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-libtorrent2、代码如下:#!/usr/bin/env pythonimport shutilimport tempfileimport os.path as ptimport sysimport libtorrent as ltfrom time import sleepdef 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 outputdef 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打开这个种子新建一个任务,然后右键点击这个任务选复制MagnetURI便把磁力连接复制到剪贴版上了很高兴回答楼主的问题如有错误请见谅